codephp Posted August 25, 2013 Share Posted August 25, 2013 (edited) please check screen shot.... for error <div> <?php require_once("sendcontact.php"); $obj = new insertcontact(); $result = $obj->recordcontact(); ?> <?echo "<center>".$result."</center><br><br>"; ?> <form action="" method="post"> <table> <th><center> Please fill the form : </center></th> <tr> <td>Name :</td> <td><input type="text" name="fullname" placeholder="Type your full name"></td> </tr> <tr> <td>email :</td> <td><input type="email" name="email" placeholder="ex: username@example.com"></td> </tr> <tr> <td>Type of contact :</td> <td><input type="checkbox" name="checkbox" value="Report" >Report <br> <input type="checkbox" name="checkbox" value="Feedback" >Feedback <br> <input type="checkbox" name="checkbox" value="Suggestions" >Suggestions <br> </td> </tr> <tr> <td>Message:</td> <td><textarea name="message" style="max-width:500px;" cols="60" rows="10" placeholder="Type message here"></textarea></td> </tr> </table> <input type="submit"> </form> </div> contact.php <?php include('dbconnect.php'); class insertcontact{ public function recordcontact(){ // function for inserting videos $Name = $_POST["fullname"]; $email = $_POST["email"]; $message = $_POST["message"]; $type = $_POST["checkbox"]; $date = new DateTime(); $contactdate = $date-> format('Y-m-d H:i:s'); if(empty($Name) || empty($email) || empty($message) || empty($type)){ return $result = "Missing information....!"; }else{ $strSQL = " INSERT INTO Contact (Name, email, message, contact_type, date ) VALUES ('".$Name."','".$email."','".$message."','".$type."','".$contactdate."')" ; try{ mysql_query($strSQL); $message = "Thank you for submitting."; return $message ; clearstatcache(); exit(); } catch(CustomException $e){ throw new Exception( 'Something really gone wrong', 0, $e); exit(); } } } } ?> Edited August 25, 2013 by codephp Quote Link to comment Share on other sites More sharing options...
codephp Posted August 25, 2013 Author Share Posted August 25, 2013 After checking preview my site, initially it showing that screen shot.... printing missing information .... may i know what's wrong. how do i validate required fields? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 25, 2013 Share Posted August 25, 2013 Make checkboxes to be optional. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted August 25, 2013 Share Posted August 25, 2013 You need to check if the form has been posted before you validate the information. <?PHP if($_SERVER['REQUEST_METHOD'] == 'POST') { // form has been posted } ?> 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.