Php Contact Form issue -
i'm having problems code. after submitting filled form display message (email sent!) not displaying next submit button. need display email sent message next submit button on contact form. after submitting form, need clear form fields after refresh or action. kindly me out code
form action images:
<?php $action=$_request['action']; if ($action=="") /* display contact form */ { ?> <form name="contactform" method="post" enctype="multipart/form-data"> <input type="hidden" name="action" value="submit"> <label for="your_name">your name <font color="red">*</font></label> <input type="text" id="reset" name="your_name" placeholder="enter name" maxlength="20" size="40" > <label for="email">email address <font color="red">*</font></label> <input type="email" id="reset" name="email" placeholder=" enter e-mail address" maxlength="20" size="40" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" required> <label for="mobile_number">mobile number</label> <input type="tel" id="reset" name="mobile_number" pattern="[0-9]{1}[0-9]{9}" placeholder="enter phone number adding country code (eg: +91.,)" maxlength="30" size="40" > <label for="message">message <font color="red">*</font></label> <textarea name="message" id="reset" placeholder="your message goes here" maxlength="1000" cols="62" rows="10" required></textarea> <input type="submit" value="submit"> </form> <?php } else /* send submitted data */ { $your_name = $_request['your_name']; $email = $_request['email']; $mobile_number = $_request['mobile_number']; $message = $_request['message']; $formcontent="from: $your_name \n email: $email \n phone number: $mobile_number \n message: $message"; $recipient = "name@email.com"; $subject = "contact form"; $mailheader = "from: $email \r\n"; if (($your_name=="")||($email=="")||($message=="")) { echo "all fields required, please fill <a href=\"\">the form</a> again."; } else{ @mail($recipient, $subject, $formcontent, $mailheader) or die("error!"); echo "email sent!"; } } ?>
you can redirect page after sent email or can set variable $msg='email sent';
, call variable before submit button.
$action=$_request['action']; if ($action!="") /* display contact form */ { $your_name = $_request['your_name']; $email = $_request['email']; $mobile_number = $_request['mobile_number']; $message = $_request['message']; $formcontent="from: $your_name \n email: $email \n phone number: $mobile_number \n message: $message"; $recipient = "name@email.com"; $subject = "contact form"; $mailheader = "from: $email \r\n"; if (($your_name=="")||($email=="")||($message=="")) { header('location: yoururl?msg=error'); //$msg = "all fields required, please fill <a href=\"\">the form</a> again."; } else{ @mail($recipient, $subject, $formcontent, $mailheader) or die("error!"); header('location: yoururl?msg=succss'); //$msg = 'email sent!'; } } ?> <form name="contactform" method="post" enctype="multipart/form-data"> <input type="hidden" name="action" value="submit"> <label for="your_name">your name <font color="red">*</font></label> <input type="text" id="reset" name="your_name" placeholder="enter name" maxlength="20" size="40" > <label for="email">email address <font color="red">*</font></label> <input type="email" id="reset" name="email" placeholder=" enter e-mail address" maxlength="20" size="40" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" required> <label for="mobile_number">mobile number</label> <input type="tel" id="reset" name="mobile_number" pattern="[0-9]{1}[0-9]{9}" placeholder="enter phone number adding country code (eg: +91.,)" maxlength="30" size="40" > <label for="message">message <font color="red">*</font></label> <textarea name="message" id="reset" placeholder="your message goes here" maxlength="1000" cols="62" rows="10" required></textarea> <?php if(isset($_request['msg']) , $_request['msg']=='success'){echo "email sent!";}if(isset($_request['msg']) , $_request['msg']=='error'){echo "all fields required, please fill <a href=\"\">the form</a> again.";} ?> <?php echo $msg; ?> <input type="submit" value="submit"> </form>
Comments
Post a Comment