Skip to content

Instantly share code, notes, and snippets.

@stavrossk
Created April 14, 2018 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stavrossk/98f801a5dc375ca6e1c240fa5b37a4c7 to your computer and use it in GitHub Desktop.
Save stavrossk/98f801a5dc375ca6e1c240fa5b37a4c7 to your computer and use it in GitHub Desktop.
Sample code to refresh a web page after form submitting using PHP.
<?php
// check if the form was submitted
if ($_POST['submit_button']) {
// this means the submit button was clicked, and the form has refreshed the page
// to access the content in text area, you would do this
$a = $_POST['update'];
// now $a contains the data from the textarea, so you can do whatever with it
// this will echo the data on the page
echo $a;
}
else {
// form not submitted, so show the form
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action -->
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" -->
</form>
<?php
} // end "else" loop
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment