Archived

This topic is now archived and is closed to further replies.

cza

newbie: PHP Required Field Help

Recommended Posts

hey, this is a problem which i have to solve quickly, so i thought i would ask the experts :D I am doing a survey and i want it to do the following things: [*]After you click the continue button it checks to see if all fields have been filled in [*]If all fields have been filled in it echos the what u have entered into the feilds (the ansers u have given) and shows them on the next page (check.php), so that u can check to make sure the answers u have supplyed are all good [*]If all is okay u click the send button at the bottom of the page and it emails it to me if that is confusing here is a little thing i made to help explain it: -----------------------------------------Page 1 Name: Date of Birth EMail [continue button] ---------------------------------------------Page 2 the following is what u have entered, is this information correct? echo $what they entered in name field echo $what entered in dob field echo $what entered in email field i hope that helps (that is an example except the questions are different here is the page code: http://calebt.recoil.net.nz/others/geo_survey2.phps here is the check page code (which was meant to check the form to make sure all feilds have been entered): http://calebt.recoil.net.nz/others/check2.phps that is the page im having trouble with any help if greatly appreciated thanks cza [edited by - cza on August 13, 2003 9:15:48 PM]

Share this post


Link to post
Share on other sites
<< After you click the continue button it checks to see if all fields have been filled in >>

PHP is simple, I use it all the time. Make sure your first HTML form is correctly pointing to your php script that does the checking. For example inside FORM, use METHOD = "POST" and ACTION="check.php"

In your check.php, use IF to verify all the fields, like this

$VALID = 1;

if ((!$A) OR (!$B) OR (!$C)) $VALID = 0;

if ($VALID) print "You entered $A $B $C Thanks for completing the form. Press submit if these are correct, otherwise go back."

else print"All the fields were not entered. Please go back."

<< If all is okay u click the send button at the bottom of the page and it emails it to me >>

Then if the info is valid above, you want to supply another submit button and have it remember the values for $A, $B, $C by printing the form to the screen and using type HIDDEN

INPUT TYPE='HIDDEN' name='A' value='$A'
INPUT TYPE='HIDDEN' name='B' value='$B'
INPUT TYPE='HIDDEN' name='C' value='$C'

and pass in your form as METHOD = "POST" and ACTION = "submit.php" or whatever for your final submission where you use the PHP mail( ) command. That should do it. You only want to print " " the second form and submit button though if $VALID = 1 (true).

Phil P

[edited by - PhilVaz on August 13, 2003 9:36:19 PM]

Share this post


Link to post
Share on other sites
thanks alot for that

i have 10 feilds currently in the survey they are done like this:

<input type="radio" name="Q1">

etc until u get to 10

to put that in the code you gave would it be this :

if ((!$Q1) OR (!$Q2) OR (!$Q3)OR (!$Q4)OR (!$Q5)OR (!$Q6)OR (!$Q7)OR (!$Q8)OR (!$Q9)OR (!$Q10)) $VALID = 0;


does that look correct

thanks

Share this post


Link to post
Share on other sites
<< does that look correct thanks >>

Yes, looks right. The "tricky" thing is you wanted a second submit button after the data was entered, so you have to pass the data a second time for $Q1 to $Q10 all as type = "HIDDEN". I believe that is how to do it, otherwise the data will not be remembered from the previous web page when you go to mail( ) it.

Phil P

Share this post


Link to post
Share on other sites
quote:
Original post by PhilVaz
<< does that look correct thanks >>

Yes, looks right. The "tricky" thing is you wanted a second submit button after the data was entered, so you have to pass the data a second time for $Q1 to $Q10 all as type = "HIDDEN". I believe that is how to do it, otherwise the data will not be remembered from the previous web page when you go to mail( ) it.

Phil P


That is indeed correct. Once you POST data to a page, any subsequent pages will have to include the data somewhere else (session variables or form variables) in order to access them. I prefer form variables as in Phil''s method described, because it is not in any way based on the client having their cookies enabled within their browser.

The downside with form variables, is that they are not as secure as cookies in terms of data validation, so make sure that you validate the data correctly. For example, don''t let the client be able to "bust out" of your hidden fields by placing a quote in the data and then create some dangerous XSS exploit by using javascript to hijack information.

It''s a simple process, but one that is often overlooked.

--hellz

Share this post


Link to post
Share on other sites
AWESOME!@#! it works

thanks alot for that

now im trying to print what they people answers were

here is the code:





$VALID = 1;

if ((!$Q1) OR (!$Q2) OR (!$Q3) OR (!$Q4) OR (!$Q5) OR (!$Q6) OR (!$Q7) OR (!$Q8) OR (!$Q9) OR (!$Q10)) $VALID = 0;

if ($VALID){
echo( "Thanks for completing the form. Press submit if the following is correct, otherwise go back.");
echo("

");
echo("Question 1: $Q1");
echo("

");
echo("Qusetion 2: $Q2");
echo("

");
echo("Question 3: $Q3");
echo("

");
echo("Question 4: $Q4");
echo("

");
echo("Question 5: $Q5");
echo("

");
echo("Question 6: $Q6");
echo("

");
echo("Question 7: $Q7");
echo("

");
echo("Question 8: $Q8");
echo("

");
echo("Question 9: $Q9");
echo("

");
echo("Question 10: $Q10"");

}

else{
echo("All the fields were not entered. Please go back.");
}
?>
</body>
</html>

now it says
"Parse error: parse error in /www/virtual/calebt.recoil.net.nz/htdocs/others/check.php on line 38"

which is the else { line

what is wrong there?


where it has echo("
") there is a < p > in there




[edited by - cza on August 13, 2003 10:06:55 PM]

Share this post


Link to post
Share on other sites
<< echo("Question 10: $Q10""); >>

You have a second quote mark after the 10.

<< Parse error: parse error which is the else { line >>

Yeah, I think its the second " mark. Also, after your last echo, you want to echo " " again a new form and submit button, passing the variables $Q1 to $Q10 all as type hidden to have them "remembered" for your mail( ). Another point: you can use simply -br- (with < > for new line in HTML) at the end, you don't have to echo" " again.

PHP is easy to learn and works well. I use it for my brother's mortgage business. PHP.net is the official site for documentation. Plenty of tips on the language and discussion there.

Phil P

[edited by - PhilVaz on August 13, 2003 10:26:10 PM]

Share this post


Link to post
Share on other sites
sweet will try now

thanks alot for help pillvaz

[edit] i have encountered another problem when im echoing the results since they are radio buttons the answers to them are "on"

this is what happens when all fields are filled out:

Question 1: on

Qusetion 2: on

Question 3: on

Question 4: on

how do i change the on to the answer they are given

e.g.

Question 1

Male (x) < radio field
Female ()

then on the next page instead of showing
Question 1 on

it shows

Question 1 : Male



[edited by - cza on August 13, 2003 10:42:00 PM]

[edited by - cza on August 13, 2003 10:53:45 PM]

Share this post


Link to post
Share on other sites
<< Question 4: on how do i change the on to yes ?? >>

Use Google dude, that's what I use for questions.

Type in "radio button HTML" and find out all about radio buttons. I think you have to add a VALUE = inside your HTML form to specify a particular value for your radio buttons.

You use this in your HTML form

input type="radio" name="Q1" value="whatever"

And when that radio is selected the variable $Q1 is whatever. Normally only one radio button can be selected in a group, so if you want to do a multiple selection thing, use check boxes instead

input type="checkbox" name="Q1" value="whoever"

And like magic, your variable $Q1 will take on the value whoever when checked.

Phil P

[edited by - PhilVaz on August 13, 2003 10:54:47 PM]

Share this post


Link to post
Share on other sites
thank you

i used google before but the answers werent specific enough for what i was asking

anyways

thank you it should be all good now

thanks for your help

Share this post


Link to post
Share on other sites