Jump to content

form validator???


ball420

Recommended Posts

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 />";
    }
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!" 





?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.