ball420 Posted August 28, 2007 Share Posted August 28, 2007 i want to make a couple of my fields required but i'm not sure how to go about it also i want to make the next step go to a url not echo just some words. thanks a million for all your help!!! Quote Link to comment Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 form.php <form action="process.php" method="post"> <input type="text" name="foo">foo? <input type="submit" name="submit"> </form> process.php <?php if (isset($_POST['submit'])) { if (empty($_POST['foo'])) { echo "foo is a required field<br />"; } } ?> Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 28, 2007 Share Posted August 28, 2007 if($_POST['name'] == ""){ echo "Please fill in the name"; } elseif($_POST['phone'] == ""){ echo "Please fill in the phone"; } else{ //make the operations } To go to a url u can use header('location: page.php') or alternatively meta refresh or javascript refresh. Quote Link to comment Share on other sites More sharing options...
ball420 Posted August 28, 2007 Author Share Posted August 28, 2007 i am still having trouble i'm a little confused on this process here is my code. i'm getting a error on line 127 which is right past my closing tag here is m code. like i said i would like a validator for a few fields and i would also like it to go to a thank you page. thanks again for the help <?php if(isset($_POST['submit'])) { if (empty($_POST['name_field'])) { echo "foo is a required field<br />"; } $to = "tony@yourmom.com"; $subject = "application"; $name_field = $_POST['name']; $age = $_POST['age']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $cell = $_POST['cell']; $ecnumber = $_POST['ecnumber']; $email_field = $_POST['email']; foreach($_POST['check'] as $value) { $check_msg .= "I am interested in: $value\n"; } //dance $yrsexp =$_POST['yrsexp']; $dexplain = $_POST['dexplain']; $tdexplore = $_POST['tdexplore']; //music $yrsexpMusic =$_POST['yrsexpMusic']; $mexplain =$_POST['mexplain']; $musicExplore=$_POST['musicExplore']; $insPlay=$_POST['insPlay']; $insLearn=$_POST['insLearn']; //acting $yrsexpAct=$_POST['yrsexpAct']; $actexplain=$_POST['actexplain']; $aexplore=$_POST['aexplore']; $aExploreW=$_POST['aExploreW']; $aExploreW2=$_POST['aExploreW2']; //education $gradeLevel=$_POST['gradeLevel']; $sdistrict=$_POST['sdistrict']; $cllisted=$_POST['cllisted']; $maother=$_POST['maother']; $body = "From: $name_field\n Age: $age\n address: $address\n City: $city\n State: $state\n Zip: $zip\n Phone: $phone\n Cell: $cell\n Emergency Contact Number: $ecnumber\n E-Mail: $email_field\n $check_msg Option: $option\n ----------------------------------------------\n DANCE\n $yrsexp years experiance\n $dexplain\n i want to explore $tdexplore \n -----------------------------------------------\n MUSIC/n $yrsexpmusic years experiance\n $mexplain\n I would like to explore $musicExplore\n I play the $insPlay \n I want to learn $insLearn\n -----------------------------------------------\n ACTING\n $yrsexpAct years experiancen\n $actexplain\n i want to explore- $aexplore i have done- $aExploreW -thus far regarding theater\n the particular style that i want to explore is $aExploreW2\n -----------------------------------------------\n EDUCATION\n my grade current grade level is: $gradeLevel\n school district: $sdistrict\n Clubs and activities involved in: $cllisted\n they found the met by: $dropdown\n $maother\n"; echo "Data has been submitted to $to!"; mail($to, $subject, $body); } else { echo "blarg!" ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 You're missing the closing } for your if-else. You just have the ?> without closing the else. Quote Link to comment Share on other sites More sharing options...
ball420 Posted August 28, 2007 Author Share Posted August 28, 2007 thanks that fixed that problem but now it echo's both foo is a required field Data has been submitted to tony@yourmom.com! thanks again fo rthe hlp Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 Well read through the code and see why that is. You never tell it anything about not sending if one of the required fields is empty. You might consider setting a variable like $ok and setting it to false if it's not okay to send the form, then check it before emailing. Quote Link to comment Share on other sites More sharing options...
Fadion Posted August 28, 2007 Share Posted August 28, 2007 Simply: if (empty($_POST['name_field'])) { echo "foo is a required field<br />"; } else{ //the other code } So u check the name_field, if is empty show the error, else make the processing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.