dennismonsewicz Posted February 8, 2009 Share Posted February 8, 2009 <?php require_once "includes/header.php"; ?> <?php if(isset($_POST['submit'])) { if(!isset($_POST['name']) || $_POST['name'] == '') { $e_name = '<span class="error">You must enter a name to continue</span>'; } else { $name = mysql_real_escape_string($_POST['name']); } if($_POST['email']) { $email = mysql_real_escape_string($_POST['email']); } if(!isset($_POST['message']) || $_POST['message'] == '') { $e_message = '<span class="error">You must enter a message to continue</span>'; } else { $message = mysql_real_escape_string($_POST['message']); } $query = mysql_query("INSERT INTO contact (name, email, message) VALUES ('$name', '$email', '$message')")or die(mysql_error()); } ?> <div class="container"> <div class="left_weight_two"> <?php include "includes/nav.php"; ?> <div class="content-left"> <?php if($query) { $to = 'dennismonsewicz@gmail.com'; $subject = 'Contact from dennismonsewicz.com'; $body = '<p>Dennis, <strong>' . $name . '</strong> has filled out your contact form and has sent you the following information.'; $body .= '<p>Email: ' . $email . '</p>'; $body .= '<p>Message: ' . $message . '</p>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; if(mail($to, $subject, $body, $headers)) { echo '<div class="alert"><img src="images/action_check.gif" alt="image" class="alertimg"/> Contact Successful! An email has been sent to Dennis Monsewicz</div>'; } } ?> <form action="contact.php" method="post"> <p> Name: <b style="color:#ff0000;">*</b> <?php echo $e_name; ?><br/> <input type="text" name="name" id="name" class="forms" style="width:250px;"/> </p> <p> Email <em>(optional)</em>:<br/> <input type="text" name="email" id="email" class="forms" style="width:250px;"/> </p> <p> Message: <b style="color:#ff0000;">*</b> <?php echo $e_message; ?><br/> <textarea rows="6" cols="50" class="forms" style="width:440px;" name="message" id="message"></textarea> </p> <input type="submit" id="contact" class="buttons" value="Submit" name="submit" /> </form> <div style="clear:both;"></div> </div> </div> <?php include "includes/right.php"; ?> <div style="clear:both;"></div> </div> <?php require_once "includes/footer.php"; ?> If you submit the form blank the form still submits and shows the contact successful message... how do i fix this so that the form does not submit if a blank form is submitted Quote Link to comment Share on other sites More sharing options...
trq Posted February 8, 2009 Share Posted February 8, 2009 Check if your form fields are empty. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 8, 2009 Author Share Posted February 8, 2009 hmmm how would i incorporate that code into my code that is already in place? Quote Link to comment Share on other sites More sharing options...
trq Posted February 8, 2009 Share Posted February 8, 2009 I'm not incorporating anything into that code because to be quite frank, its pretty hard to follow. You should use spaces to indent, tabs or whatever it is your using create far too much whitespace. Anyway, most of the logic seems to be already there, your just not stopping execution If you have error messages. I would use an array to store your error messages then stop the script form executing if the array has values. eg; $errors = array(); if (!isset($_POST['foo'] || $_POST['foo'] == '') { $errors[] = "foo is empty"; } else { $foo = $_POST['foo']; } // more checking. // process. if (count($errors)) { // display errors. foreach ($errors as $error) { echo $error; } exit(); } else { // process form. } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 8, 2009 Author Share Posted February 8, 2009 excuse all of my "whitespace" in my code... i like to have everything tabbed out... for me its easier to follow. But I fixed my issue.. thanks again! 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.