Irresistable Posted November 13, 2009 Share Posted November 13, 2009 I have a form with numerous error fields, They all work as they should do I believe. However.. if the message string is below 10, it still sends the email I'm not sure why. Here is my code <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="en-UK" > <meta name="description" content="Developers Community is a Community for developers to discuss and provide support for development. We have forums that allow users to participate in polls, giving the support to other users, or you may perhaps share your knowledge so that others can learn from you. Additionally, we have tutorials which cover a wide aspect of all scripts, from HTML to PHP to C++" > <meta name="keywords" content="script help, script forums, script tutorials, script tutorial, script snippets, script, help, resources, snippets, tutorials, web development, programming, development, community, developers community, php, c++, c#, MySQL, database, databases, VB, Java, Javascript, support" > <title>Developers Community - Contact Us</title> <link href="styles/twoColLiqRtHdr.css" rel="stylesheet" type="text/css" /> <link rel="shortcut icon" href="images/favicon.ico"> <link rel="icon" href="images/favicon.ico"> <!--[if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColLiqRtHdr #sidebar1 { padding-top: 30px; } .twoColLiqRtHdr #mainContent { zoom: 1; padding-top: 15px; } /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> </head> <body class="twoColLiqRtHdr"> <div id="container"> <div id="header"> <div class="twoColLiqRtHdr" id="logreg"> <?php if(isset($_SESSION['s_logged_n'])) { echo('<strong>'.ucwords($_SESSION['s_username']).' - <a href="member.php">My Account</a> - <a href="logout.php">Logout</a></strong>'); } else { ?> <strong><a href="login.php">login</a> // <a href="register.php">register</a></strong> <?php } ?> </div> </div> <div> <ul id="navigator"> <li><a href="/">Home</a></li> <li><a href="tutorials.php">Tutorials</a></li> <li><a href="jobvac.php">Job Vacancies</a></li> <li class="active"><a href="contactus.php">Contact Us</a></li> <li><a href="forums">Forums</a></li> <div id="time" style="font-size:12px";> <script type="text/javascript"> var d=new Date() var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December") document.write(weekday[d.getDay()] + " ") document.write(d.getDate() + " ") document.write(monthname[d.getMonth()]) </script> </div> </ul> <div class="twoColLiqRtHdr" id="topbar"> </div> </div> <div id="sidebar"> <div id="updates"> <h3 style="margin:0px;">Recent News</h3><br /> <?php include("Updates/updatediv.php"); ?> <br /> </div> <div class="twoColLiqRtHdr" id="advertisement"> <h2><br /> <br /> <br /> Want your advert here? Contact us.<br /> <br /> <br /> <br /> </h2> </div> </div> <div id="mainContent"> <?php if($_SESSION['s_logged_n'] == 'true'){ ?> <div class="twoColLiqRtHdr" id="introduction"> <h1>Contact Us</h1> <p>You may use this page to contact us for any Enquiries, Problems, Complaints and Job related stuff. Just fill in the form below.<br /> <br /> May take up to 24 hours for a reply, 48 hours if we're busy.<br /> If you do not select a Subject, the email will be ignored, and you will not get a reply!</p> </div> <center> <?php include("config.php"); if(isset($_POST['submit'])) { $sjt = $_POST['subject']; if(!$sjt || strlen($sjt = trim($sjt)) == 0){ echo("<strong>Error. Subject is required!<br /></strong>"); } $msg = $_POST['message']; if(!$msg || strlen($msg = trim($msg)) == 0){ echo("<strong>Error. Message is required!<br /></strong>"); } else { if(strlen($subuser) < 10){ echo("<strong>Error. Your mail is too short!<br /></strong>"); } } $user_code = $_POST['captcha']; if (strlen($user_code) == 0){ echo("<strong>Error. Captcha is required!<br /></strong>"); } else { if (strcmp(md5($user_code),$_SESSION['ckey'])){ echo("<strong>Error. The captcha you entered is incorrect!<br /></strong>"); } } if($_POST['subject'] && $_POST['message'] && $user_code) { $username = ucwords($_SESSION['s_username']); $query = mysql_query("SELECT Email FROM Users WHERE Username = '$username' LIMIT 1") or die(mysql_error()); $user = mysql_fetch_array($query); $to = "[email protected]"; $subject = $sjt; $name = $username; $email = $user['Email']; $message = $msg; $header="from: $name <$email>"; $body = "$message\n\n $name"; echo "Your mail has been sent. You'll recieve a reply in 24 hours, 48 hours on busy days."; mail($to, $subject, $body, $header); } }?> <form method="post"> <table width="50%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="25%">Subject*</td> <td width="25%"><label> <select name="subject" id="subject"> <option selected="selected"></option> <option>General Questions</option> <option>Advertising</option> <option>Job Questions</option> <option>Applying For A Job</option> <option>Reporting A Problem</option> <option>Complaints</option> </select> </label></td> </tr> <tr> <td>Message*</td> <td><textarea name="message" cols="60" rows="10" class="textBox" id="message"></textarea></td> </tr> <tr> <td><span class="style3"><img src="pngimg.php" alt="" width="88" height="32" align="middle" /></span></td> <td><input name="captcha" class="textBox" id="captcha" size="29" maxlength="10" /></td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" class="textBox" value="Submit" /></td> </tr> </table> </form></center> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> </p> <?php } else { echo('<br />This page is only avaliable to members. Please <a href="login.php">Login</a> or <a href="register.php">Register</a> if you have not already done so.'); } ?> </div> <br class="clearfloat" /> <div id="footer"> <p>Developers-Community © 2009 - <a href="contactus.php">Contact</a></p> <!-- end #footer --></div> <!-- end #container --> </div> </body> </html> The bit which is smaller than 10, is the bit below, also in the code above. $msg = $_POST['message']; if(!$msg || strlen($msg = trim($msg)) == 0){ echo("<strong>Error. Message is required!<br /></strong>"); } else { if(strlen($subuser) < 10){ echo("<strong>Error. Your mail is too short!<br /></strong>"); } } Can you help me out, cheers. Link to comment https://forums.phpfreaks.com/topic/181442-solved-why-does-the-form-submit-aswell-as-giving-an-error/ Share on other sites More sharing options...
mrMarcus Posted November 13, 2009 Share Posted November 13, 2009 because you have just set it to echo "<strong>Error. Your mail is too short!<br /></strong>" if the message is too short. $_POST['message'] is still set even if it has too few characters. i also don't see where you've set $subuser .. you have it in your check for 10 or less characters. you're best to do something like this: <?php if (strlen ($_POST['message']) < 10) { $errors['message'] = 'Error. Your mail is too short!'; } if (!is_array ($errors)) { //do mail, etc; } else { //display errors; } ?> Link to comment https://forums.phpfreaks.com/topic/181442-solved-why-does-the-form-submit-aswell-as-giving-an-error/#findComment-957148 Share on other sites More sharing options...
Irresistable Posted November 13, 2009 Author Share Posted November 13, 2009 Oh! that might be why because its set as $subuser Link to comment https://forums.phpfreaks.com/topic/181442-solved-why-does-the-form-submit-aswell-as-giving-an-error/#findComment-957159 Share on other sites More sharing options...
Irresistable Posted November 14, 2009 Author Share Posted November 14, 2009 I did it so it was if (clear($sjt) && etc etc Link to comment https://forums.phpfreaks.com/topic/181442-solved-why-does-the-form-submit-aswell-as-giving-an-error/#findComment-957167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.