Page 1 of 1

Form submit after validation without java

Posted: Fri Nov 24, 2006 8:30 pm
by me!
Ok I have a form, (form.php) and uppon submit

Code: Select all

<form name="reg" method="post" action="form.php">
The PHP validation works nice :) , but now what... I would like it to go to a confirmation page that shows the user what they entered and askes them to confirm it. If anaything is wrong they can use there back button to edit it and the form willbe validated again and the user shown the confirm page again. If everything is ok they hit the continue button on the confirm page a o to paypal.

this is what I have if the vallidatation passes:

Code: Select all

// display error message if any, if not, proceed to other processing
	if($error_msg==''){
		// other process here
			} else {
		echo "<p class=\"important\">$error_msg</p>";
	}
I have fornd a few ways to do it with java, but I dont want to use java...

I did try:

Code: Select all

// display error message if any, if not, proceed to other processing
	if($error_msg==''){
		// other process here
		$vallpass = 'yes'; // if form passes vallidation 
	} else {
		echo "<p class=\"important\">$error_msg</p>";
	}

if ( "$vallpass" == 'yes'){	
	$action = 'confirm.php'
	} else { 
	$action = 'form.php'
	}

Code: Select all

<form name="reg" method="post" action="<?php echo "$action";?>">
But that did not validate the form the secount time the user edited it :(

Posted: Fri Nov 24, 2006 8:40 pm
by evilchris2003
anything submitted in a form can be retrieved using

$_POST

like so

Code: Select all

if(isset($_POST['name'])) 
       {
       echo $_POST['name'];
       }
else
       {
          echo 'you forgot to enter your name';
       }

Posted: Fri Nov 24, 2006 8:53 pm
by me!
I know, I like to make the form information vars to keep it shorter. So in the begining of the page i have a lot of

Code: Select all

$name = $_POST["name"];

Posted: Fri Nov 24, 2006 9:02 pm
by evilchris2003
That is the easiest way of doing it and $_POST['name']; is a variable in its own right

Code: Select all

echo 'Welcome', $_POST{'name'];
will return the same as

Code: Select all

echo 'Welcome', $name;
having defined what you last posted

Posted: Sat Nov 25, 2006 8:37 am
by me!
So any ideas on the submit question?

Posted: Sat Nov 25, 2006 2:11 pm
by me!
Please... :?:

Posted: Sat Nov 25, 2006 3:31 pm
by evilchris2003
if you want to retrieve anything submitted from the form use the same syntax as above
where the sumbit button is named submit

Code: Select all

if (isset($_POST['submit']))

Posted: Sat Nov 25, 2006 3:32 pm
by Chris Corbyn
evilchris2003 wrote:if you want to retrieve anything submitted from the form use the same syntax as above
where the sumbit button is named submit

Code: Select all

if (isset($_POST['submit']))
IE 6 does not send this info unless the button clicked with the mouse. Hitting the enter key will not send the submit value. Just FYI ;)

Posted: Sat Nov 25, 2006 3:39 pm
by evilchris2003
Ah the things you learn i was unaware of this

how do you solve it using enter i mean?

Posted: Sat Nov 25, 2006 3:44 pm
by Chris Corbyn
evilchris2003 wrote:Ah the things you learn i was unaware of this

how do you solve it using enter i mean?
I just check for a hidden form field or maybe even one of the required fields.

Posted: Sat Nov 25, 2006 3:47 pm
by evilchris2003
Ok i already have the forms im using check for empty fields

Posted: Sat Nov 25, 2006 4:00 pm
by me!
GOT IT!

I just added:

Code: Select all

<input type="hidden" name="process" value="1">
to the first form and some if statements then called the forms as includes, and all is good!

Thanks guys!