Form Validation Mulitpage question - Please help me!!!

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
foot01
Forum Newbie
Posts: 2
Joined: Fri Jul 24, 2009 7:46 pm

Form Validation Mulitpage question - Please help me!!!

Post by foot01 »

Hello -

I am new to PHP and I am building a muliti-page form. I'm having issues validating my form and submitting variables to the next page.

I am getting an error when it the form tries to validate - Notice: Undefined index: q01 on line 17

I have two questions:

1. How do I validate and send these vars to the next page?
2. The next form is called form02.php. Do I put that in the form action call?
ie. <form name="form1" method="post" action="form02.php">

Any help would be great!

Here is my example --->

<?PHP
// start session
session_start();

// check if radio button is selected after submit
if(isset($_POST['submit'])) {

if (!$_POST['q01'])
echo "Question 1 is required";
} else {

?>

<form name="form1" method="post">
Question One:
<input type="radio" name="q01" value="No" />No
<input type="radio" name="q01" value="Yes" />Yes
<input type="radio" name="q01" value="Maybe" />Maybe

<input type="submit" name="submit"value="Send">

</form>

<?php }

?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Form Validation Mulitpage question - Please help me!!!

Post by jackpf »

You should use isset() if you don't want the error.

And what do you mean...you want to forward the user to another form?
johniem
Forum Commoner
Posts: 29
Joined: Mon Jul 20, 2009 8:58 am

Re: Form Validation Mulitpage question - Please help me!!!

Post by johniem »

If you want to redirect the user to another form after the first one you have to do it after you proccess the users input .. So when the user submits the form you will
get the inputs at the server side, proccess the user's inputs and then you can display the new form to the client. You can to this at the same script like the form02.php you mention.
Php has some very nice form validation capabilities.Just search the net and you will find many of them.

Hope this helps.
foot01
Forum Newbie
Posts: 2
Joined: Fri Jul 24, 2009 7:46 pm

Re: Form Validation Mulitpage question - Please help me!!!

Post by foot01 »

I'm doing a multi-page form - there are about 4 steps in the process.

I am not sure about the reply regarding process the variables first as mentioned above.

Can some elaborate more on this?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Form Validation Mulitpage question - Please help me!!!

Post by jackpf »

You need to do whatever you want to do with the posted data, and then redirect to the next form, I think was the jist of it.
Post Reply