ZeroError Posted November 28, 2009 Share Posted November 28, 2009 I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand, so, if I may, I'd like to ask quite a specific question. I'm creating a contact form, and I need to make sure all of the elements are filled in: if(isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['from']) && $_POST['comment'] != "Enter your message here.") { //send me an email; } else { //Tell the user to fill everything in; } I've tested the code a few times, but it keeps executing the else. I've checked it a few times, and I can't understand why. Quote Link to comment https://forums.phpfreaks.com/topic/183201-operator-precedence-assistance/ Share on other sites More sharing options...
Zane Posted November 28, 2009 Share Posted November 28, 2009 Are you sure that you have everything named correctly.. what does your HTML form look like? another way to check these kind of things is this $formSuccess = false; foreach($_POST as $formElement => $value) { if(isset($_POST[$formElement]) $formSuccess = true; else $formSuccess = false; //Then for the comment one. if($formElement == 'comment' && $value == 'Enter your message here.') $formSuccess = false; } if($formSuccess) { //send mail } else { // Error } or even shorter $formSuccess = false; foreach($_POST as $formElement => $value) { $formSuccess = isset($_POST[$formElement]); if($formElement == 'comment' && $value == 'Enter your message here.') $formSuccess = false; } if($formSuccess) { //send mail } else { // Error } Quote Link to comment https://forums.phpfreaks.com/topic/183201-operator-precedence-assistance/#findComment-966853 Share on other sites More sharing options...
ZeroError Posted November 28, 2009 Author Share Posted November 28, 2009 This is the entire thing, sorry if it's a bit untidy! <html> <head> <link rel="stylesheet" type="text/css" href="../includes/style1.css"> <title>Contact ZeroError</title> </head> <body> <img src="../img/gradient_bg.jpg" id="bg"> <div id="content"> <h2><div style="color: #FF0000;">Contact handler under construction. Bear with me a while!</div></h2> <table width="100%" height="100%"> <tr> <td height="100%" width="100%" align="center" valign="middle"> <?php if(isset($_GET['act']) && $_GET['act'] == 'post') { if(isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['from']) && $_POST['comment'] != "Enter your message here.") { $headers = "From: ZeroError Contact Form <contactform@zeroerror.co.uk>\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1'; $message = '<p><u>Message sent via <a href="http://zeroerror.co.uk/public/contact.php">contact form</a>.</u></p>'."\r\n"; $message .= '<table>'; $message .= '<tr><td width="200"><b>From:</b></td><td width="600">'.$_POST['name'].'</td></tr>'."\r\n"; $message .= '<tr><td width="200"><b>Address:</b></td><td width="600"><a href="mailto:'.$_POST['from'].'"</td></tr>'."\r\n"; $message .= '<tr><td width="200"><b>Message:</b></td><td width="600">'.$_POST['comment'].'</td></tr>'."\r\n"; $message .= '<tr><td width="200"><b>IP:</b></td><td width="600"><a href="http://zeroerror.co.uk/admin/banip.php?ip=' . $_POST['ip'] . '&source=contact">Ban</a></td></tr>'; $message .= '</table>'; mail("suicidalparrot@hotmail.co.uk", "Contact Form Sent", $message, $headers); echo "<h2>Message sent! Thank you for your feedback =]</h2>"; exit(0); } else { echo '<h2>All fields must be completed.</h2>'; exit(0); } } ?> <form method="POST" action="?act=post"> <h2>Contact ZeroError!</h2><br /> <h3>All fields are required.</h3><br /> <p> <h3>Your name:</h3> <input name="name" type="text" size="30" /> </p> <p> <h3>Your email address:</h3> <input name="from" type="text" size="50" /> </p> <p> <h3>Your message:</h3> <textarea name="message" cols="50" rows="5" maxlength="500">Enter your message here.</textarea> </p> <p> <h3>Your IP address:</h3> <textarea name="ip" cols="15" readonly><?php echo($_SERVER['REMOTE_ADDR']); ?></textarea> </p> <p> <input type="submit" value="Submit" name="submit"><input type="reset" value="Reset" name="reset"> </p> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/183201-operator-precedence-assistance/#findComment-966855 Share on other sites More sharing options...
Zane Posted November 28, 2009 Share Posted November 28, 2009 This is your "comment" box... I'm assuming Enter your message here. Notice that it's named message? Notice below how you're not looking at message.... but "comment"... which doesn't exist OST['name']) && isset($_POST['comment']) && isset($_ Quote Link to comment https://forums.phpfreaks.com/topic/183201-operator-precedence-assistance/#findComment-966858 Share on other sites More sharing options...
ZeroError Posted November 28, 2009 Author Share Posted November 28, 2009 Ah, I just got that. Didn't look carefully enough. Thanks very much! You see that readonly text area with the IP in it? Do you happen to know how to make it only one line? I can't find out how, I've tried rows="0", but that just gives about two lines. Quote Link to comment https://forums.phpfreaks.com/topic/183201-operator-precedence-assistance/#findComment-966861 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.