zang8027 Posted May 8, 2009 Share Posted May 8, 2009 I have dont many of these but i do not see why this is not working. Its a simple form validation. It simply posts to a process page that checks to see if everything is filled out. It is showing "noName" no matter what and all my errors are being echoed.. as if the "if statement" is not working <form action='processEmail.php' method='get'> <p>Your Name * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noName') { echo "<span class='redText'>You must enter a name</span>"; } } ?></p> <input type='text' name='uName' class='for'/> <p>Your Email * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noEmail') { echo "<span class='redText'>You must enter an email</span>"; } elseif($_GET['error']='invalid') { echo "<span class='redText'>You must enter a valid email</span>"; } } ?></p> <input type='text' name='email' class='for' /> <p>Type a Message * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noComment') { echo "<span class='redText'>You must enter a Message</span>"; } } ?></p> <textarea name='uMsg' class='for'></textarea> <br/> <br/> <input type='submit' value='Send it!'/> </form> and my process page: <?php //grab variables being passed and put them into usable variables $name = $_GET['uName']; $email = $_GET['email']; $text = $_GET['uMsg']; //Validate each field for being blank or wrong character if($_GET['name'] == "") { header("Location:contact.php?error='noName'"); } elseif($_GET['email'] == "") { header("Location:contact.php?error='noEmail'"); } elseif($_GET['comment'] == "") { header("Location:contact.php?error='noText'"); } elseif(!preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) { header("Location:contact.php?error='invalid'"); }else{ //If all checks out, send the email Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Forgot how to do comparisons? if($_GET['error'] = 'noName') That is just an assignment. It's always true unless you're assigning empty values. Use 2 or 3 equal signs for comparison. You have a bunch of these IF statements. Fix them all. Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 thought so but i tried 2 earlier and it was still sending back ;noName' all the time Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 now i changed it to say if ['error'] == "") { do stuff here} no matter what the error, its not firing whats inside the brackets Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Please post an updated version of your code. Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noName') { echo "<span class='redText'>You must enter a name</span>"; } } ?> anything wrong with this code? Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 http://gregsreid.com/contact.php?error='noName' thats what im getting via url if i dont add the name Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Syntactically no. But if the echo does run, the output string is *not* xHTML-compliant. Your process page has its GET variables all mixed up. Correct those. Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 I fixed one problem... im dumb... my process page was copied from another one i made and the validation was wrong I still am not seeing the text though in my if statements Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Please post an updated version of your code. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2009 Share Posted May 8, 2009 Except for the 'email' field, none of your other form field names match the names you are using in the tests. For example, form field - uName and testing code - if($_GET['name'] == "") You in fact have a statement $name = $_GET['uName']; but $name is then not being used. You need to go through your code and check it for consistency. Quote Link to comment Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 <?php //grab variables being passed and put them into usable variables $name = $_GET['uName']; $email = $_GET['email']; $text = $_GET['uMsg']; //Validate each field for being blank or wrong character if($_GET['uName'] == "") { header("Location:contact.php?error='noName'"); } elseif($_GET['email'] == "") { header("Location:contact.php?error='noEmail'"); } elseif($_GET['uMsg'] == "") { header("Location:contact.php?error='noText'"); } elseif(!preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) { header("Location:contact.php?error='invalid'"); }else{ //If all checks out, send the email //------------------Email----------------- //define the receiver of the email $to = "ty@leaderexcelsolutions.com"; //define the subject of the email $subject = 'A message from'.$name.'via www.GregSReed.com'; //define the message to be sent. Each line should be separated with \n nl2br($EmailBody = $text); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $date = date("m/d/Y H:i:s"); $EmailFooter = "<br />Sent: $date<br /><br />"; $Message = $EmailBody.$EmailFooter; $ok = mail($to, $subject, $Message, $headers . "From:$name <".$to.">"); if($ok){ header("Location:contact.php?status=Success"); }else{ } } //End the else all validated ?> <?php include('header.php') ?> <div id='contact'> <?php if(isset($_GET['status'])) { if($_GET['status'] == 'success') { print "<h2>Success! Your message was sent.</h2>"; } } ?> <p class='yellowText'>Got a question or comment? Simply fill out the form below!</p> <form action='processEmail.php' method='get'> <p>Your Name * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noName') { print "<span class='redText'>You must enter a name</span>"; } } ?></p> <input type='text' name='uName' class='for'/> <p>Your Email * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noEmail') { echo "<span class='redText'>You must enter an email</span>"; } elseif($_GET['error'] =='invalid') { echo "<span class='redText'>You must enter a valid email</span>"; } } ?></p> <input type='text' name='email' class='for' /> <p>Type a Message * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noComment') { echo "<span class='redText'>You must enter a Message</span>"; } } ?></p> <textarea name='uMsg' class='for'></textarea> <br/> <br/> <input type='submit' value='Send it!'/> </form> </div> <?php include('footer.php') ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 1. I don't understand why you store them in variables if you're going to call $_POST again in the IF statement. 2. Don't put those single quotes in the redirect. What is this? 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.