How can I display an alert or a message after a user clicks a submit button in a form?
I want the alert to show when the page has loaded after the submit button has been clicked.
When submit form is clicked its goes to another php page updated the db and and redirected to the form page itself. I am doing it in PHP. Is there anyway I can post data, check in the form page and display a hidden message?
header('Location: http://www.xxxxxx.co.uk/NottTest/editqr.php');
This is the redirect link after updating the DB, can I parse a message here?
This is the page where the db is updated ..
<body>
<p>
<?php $sltdtpst= $_POST["qrtopic"]; ?>
<?php $selctsm= $_POST["qrsubmenu"]; ?>
<?php $selcttxt= $_POST["text12"]; ?>
<?php
$link = mysql_connect('www.xxxxx.co.uk', 'xxxxxx', 'xxxx');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("web3fffasd", $link);
$update = "UPDATE qr_table SET $selctsm = '$selcttxt' WHERE id_qr= $sltdtpst";
mysql_query($update, $link);
mysql_close();
header('Location: http://www.xxxxxx.co.uk/NottTest/editqr.php');
?>
</p>
</body>
So after updating the database a hidden should be displayed here in the form page
<form name="updateqrnew" form action="edider1.php" onsubmit="return validateForm()" method="post">
<div class="form_description">
Update Contents for QR below
</div>
<ul >
<li id="li_2" >
<label class="description" for="element_2">Quick refresher topics </label>
<div>
<select class="element select medium" id="qrtopic" name="qrtopic">
<option value="" selected="selected"></option>
<option value="1">Anxiety</option>
</select>
</div>
</li> <li id="li_3" >
<label class="description" for="element_3">Submenu </label>
<div>
<select class="element select medium" id="qrsubmenu" name="qrsubmenu">
<option value="" selected="selected"></option>
<option value="start_of">Starting off</option>
</select>
</div>
</li> <li id="li_4" >
<label class="description" for="element_4">Enter the article below</label>
<div>
<textarea id="text12" name="text12" class="element textarea medium"></textarea>
</div>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="431595" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Update" />
</li>
</ul>
</form>
Let me see if I understand this
and you want to inform the user that their update worked, is that it?
In this case, what you may want to look at is passing a result code from the action script to the redirect script. Then the redirect script can lookup the result code passed in a emit the proper message to the user. (Does not have to be a pop-up, necessarily in this scenario.) Passing the result code can be done in a few ways, including using the query string, or using a cookie, or using sessions. The first is easy, but makes for a slightly more messy URL. The second is rather deprecated. The third is the more generally accepted way of doing this, but if this is the only place you’d need a session, is probably overkill for your application.
Using the query string, your redirect may look like this:
where 1 can be a code for sucess, for example, or you could have other codes if there was an error you wanted to display, etc. If you need more information than just a code, you can pass that on the query string as well. Note that this does present some application security issues, so you have to ensure that your code will do the right thing if someone simply calls the redirect script directly with a query string that means something has happened in your application. That is why it’s not the best way to do this.