[FX.php List] Multiple Page Forms: Unsetting submit button
Bob Patin
bob at patin.com
Wed Jul 19 19:10:34 MDT 2006
I'm not sure why you're checking to see if the SUBMIT button was set.
If they don't click it, they'll never arrive at the 2nd page of the
form.
If you're concerned about anyone getting to page 2 without going thru
page 1, you can set a session variable on the 1st page, which
essentially says, "This user did go to page 1." To do that, use this
at the very top of your code:
session_start();
$_SESSION['valid']='Y'; //this could be any value; just so you have a
variable that you can check on subsequent forms.
On form 2 and so on, you'd put something like this:
session_start();
if(isset($_SESSION['valid']){
<< form stuff goes inside the brackets
}else{
echo "You are not authorized to view this page.";
}
Now, on to the verification stuff: I just use this for each field:
if(isset($_POST['firstname']){
}else{
echo 'Please enter a first name.';
include_once('back_to_form1.php'); //kicks them back before a record
is created
}
or I use
if(strlen($_POST['firstname']<1){
echo 'Please enter a first name.';
include_once('back_to_form1.php'); //kicks them back before a record
is created
}
There may be more elegant ways to do field checking, but this seems
to work fine for me...
Bob Patin
Longterm Solutions
bob at longtermsolutions.com
615-333-6858
http://www.longtermsolutions.com
CONTACT US VIA INSTANT MESSAGING:
AIM or iChat: longterm1954
Yahoo: longterm_solutions
MSN: tech at longtermsolutions.com
ICQ: 159333060
On Jul 19, 2006, at 7:39 PM, Jonathan Schwartz wrote:
> Moving ahead slooooooooowly with my multiple page form project...
>
> I am using the code (below) for form validation. The code appears
> on the top of the form pages. It uses isset to see if the
> submit_form button was set. The problem is now that I have moved
> to the second form page, how do I get the "submit_button" to get
> unset. I did try unset('submit_button'), but I'm unclear whether
> this is the right way to go, and if so, where to put the unset
> command. I feel that I have to Unset while on the createrecord.php
> page, just after a succesfull record creation before, but before
> the form2.php is loaded.
>
> The pages go: form1.php-->createrecord.php--->form2.php.
>
> Code from form2.php:
>
> <?
> // only validate form when form is submitted
> if(isset($_POST['submit_button'])){
> $msg='';
> if(trim($_POST['Reg1NameFirst'])==''){
> $msg.="Please enter a First Name.<br>";
> }
> if(trim($_POST['Reg1NameLast'])==''){
> $msg.="Please enter a Last Name.<br>";
> }
> /*
> if(trim($_POST['Reg1Session1'])==''){
> $msg.="Please select a Session.<br>";
> }
> if(trim($_POST["Contact1Email"])=='') {
> $msg.="Please enter an email<br>";
> } else {
> // check if email is a valid address in this format
> username at domain.com
> if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-
> z]", $_POST["Contact1Email"])) $msg.="Please enter a valid email
> address<br>";
> }
> */
> // display error message if any, if not, proceed to other processing
> if($msg==''){
> include('form3.php');
> exit;
> } else {
> #echo "<font color=red>$msg</font>";
>
> }
> }
> ?>
>
>
> TIA,
>
> Jonathan
> --
>
> Jonathan Schwartz
> Schwartz & Company
> 817 Marin Drive
> Mill Valley, CA 94941
> Phone: 415-381-1852
> jonathan at eschwartz.com - http://www.eschwartz.com
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list