Form submit after validation without java

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Form submit after validation without java

Post 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 :(
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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';
       }
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post 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"];
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post by me! »

So any ideas on the submit question?
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post by me! »

Please... :?:
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post 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']))
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Ah the things you learn i was unaware of this

how do you solve it using enter i mean?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Ok i already have the forms im using check for empty fields
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post 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!
Post Reply