How would you go about creating a preview button for a form using PHP & MySQL.
When a form is submitted to a PHP script, the information from that form is automatically made available to the script. There are many ways to access this information. The norm is to insert it directly into a database.
If I am understanding you correctly, then you should be able to get user input data directly via a GET or POST method.
Have a read through the PHP Documentation for Variables from External Sources
get user input data directly via a GET or POST method.
and then create 2 "if" loop like wise
if($_POST['preview'])// after completing the fields preview is clicked.
{
//display the preview.... and provide a submit button in this preview
}
NOTE: the submit should also b available in form where INPUT is given , i.e , there should be three buttons, Submit, Preview and Reset..
if($_POST['submit'])
{
//Finally,submit the values into the database..
//if needed redirect to the page of final display of form values...
}
In case you need guidance: you can implement a submit button that takes the user to a preview page first, and in that page you can display what the user has entered first. Add a submit button there that allows the user to actually submit the input to the database. You can even add another link, or print the form again, to let the user edit the input before previewing again and submitting.
The coding aspect of it is pretty much covered in the link provided by RussellDias. Good luck!
<script language="JavaScript">
<!--
function formpreview(form) {
form.target='_blank';
form.action='preview.php';
form.submit();
}
//-->
</script>
<input type="button" value="preview" onclick='formpreview(this.form)'>
then use $_POST
array values in the preview.php
to populate the template