Helpful Information
 
 
Category: PHP Development
form confirmation

Could someone give me a little snippet of sample code to get me rolling? I have a form and I would like to have a confirmation page show up first before sending the form off to the mysql d-base. Like this.
--------------
You have submitted the following info:
blah
blah
blah
Is this correct Yes/No
--------------
Yes - send on the form info to the d-base
No - returns you to the form

Hi gszczyrb!

I'm already a newbie to php, but i would try something like this:

This is the code of my "confirm.phtml" file

<?php

switch ($action)
{
case 'ask':
echo "Values correct?";
echo "<br>Name: ".$name;
echo "<br>Age: ".$age;
echo "<br><a href=confirm.phtml?action=yes>Yes</a>n";
echo "<br><a href=formular.html>No</a>n";
break;

case 'yes':
$sql_query = "INSERT [....]";
// execute SQL-query here
break;
}

?>

You have to call the skript from your form-file with the parameter "ask" (like: <form action=confirm.phtml?action=ask method=post>

Ok, there is one bug, if you select no, you go back to your form (he!), but the form is empty :-(

so far...
Martin

I forgot to mention. I'm using a GET method, not a POST method. This probaly makes a difference I guess.

This is how i would do it.

Form.php3 firstly looks like this...
<html><body>
<?
{
echo "
<form method="post" action="confirm.php3">
<input type="text" name="name" value="$name">
<input type="text" name="age" value="$age">
<input type="text" name="height" value="$height">
<input type="submit" name="Submit" value="Submit"></form>";
}
?>
</body></html>


Form.php3 then goes to confirm.php3 which looks like this.

<html><body>
You have submitted the following info:
<?
{
echo "age: $age<br> name: $name<br> height: $height<br>

Is this information correct?
<a href="submit.php3?age=$age&name=$name&height=$height">Yes, go on</a><br>
<a href="form.php3?age=$age&name=$name&height=$height">No, go back</a>
";
}
?>

If yes is selected, it goes to submit.php3 where the variables are added to mysql.

If no is selected, it goes back to form.php3 where the information the user previously entered will be found as the default in the textboxes.

submit.php3 is simply a page which has the code to add the variables to MySQL and says..."Thankyou, your information has been entered"

I have not tested this but it should work ok.

Let me know
Basil

Thanks to both of you. Martin I wasn't able to get yours to work, but that is probably just my amateurness showing. I do understand more about 'switch' now though. Thanks.

Tantrum, I used your script and it works great. Exactly what I was looking for. Thanks.

One more question. In the final part, when it passes the variables to submitform.php, is there a limit on the number of varaibales I can pass? It worked fine in my test dbase with only six variables, but my real dbase has over 40 variables.

Thanks again

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by gszczyrb:
One more question. In the final part, when it passes the variables to submitform.php, is there a limit on the number of varaibales I can pass? It worked fine in my test dbase with only six variables, but my real dbase has over 40 variables.

Thanks again[/quote]

I dont think so gszczyrb. There probably is a limit...but i think 40 or 50 should work fine http://www.devshed.com/Talk/Forums/smile.gif

Basil

The maximum length you can pass thru an URL is about 2.000 characters (i've read this in the german book "php - Grundlagen und Loesungen") And everything counts even variable names, values and seperators.

Martin










privacy (GDPR)