Guest User

Untitled

a guest
Apr 26th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1.  
  2. // Enter short code [contact] in post or page where you want to use the form
  3.  
  4. add_shortcode('contact','custom_contact_form');
  5.  
  6.  
  7. function custom_contact_form(){
  8. ///Check if the form is submitted
  9. if (isset($_POST['w2lsubmit'])){
  10.  
  11. //Destination email
  12. $destination="robin@abc.com";
  13. $message="First Name: ".$_POST['first_name']."\nLast Name: ".$_POST['last_name']."\nEmail: ".$_POST['email']."\nPhone: ".$_POST['phone']."\nCity: ".$_POST['city']."\nState: ".$_POST['state']."\nCountry: ".$_POST['country']."\nDescription: ".$_POST['description'];
  14. $sender=$_POST['email'];
  15. $subject="contact from\r".$sender;
  16. $headers='From:'. $sender."\r\n".'Reply-To:'.$sender;
  17.  
  18. mail($destination,$subject,$message,$headers);
  19.  
  20. ?>
  21.  
  22. <!--If the form is submitted-->
  23. Thank you for message
  24.  
  25. <?
  26. }
  27.  
  28.  
  29. else{
  30. //Before form submission we need to display form
  31. custom_contact_form_html();
  32. }
  33. }
  34.  
  35.  
  36.  
  37. function custom_contact_form_html(){
  38. ?>
  39.  
  40. <script type="text/javascript">
  41. function checkform(){
  42.  
  43.  
  44. var x=document.forms["cform"]["first_name"].value;
  45. if(x==""){
  46. alert("Please Enter First Name");
  47. return false;
  48. }
  49. var x=document.forms["cform"]["last_name"].value;
  50. if(x==""){
  51. alert("Please Enter Last Name");
  52. return false;
  53. }
  54.  
  55.  
  56.  
  57. var x=document.forms["cform"]["email"].value;
  58. var atpos=x.indexOf("@");
  59. var dotpos=x.lastIndexOf(".");
  60. if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  61. {
  62. alert("Not a valid e-mail address");
  63. return false;
  64. }
  65. var x=document.forms["cform"]["country"].value;
  66. if(x==""){
  67. alert("Please Enter Country");
  68. return false;
  69. }
  70. }
  71. </script>
  72.  
  73.  
  74.  
  75. <form method="post" class="w2llead sidebar" action="<? the_permalink() ?>" name="cform" onsubmit="return checkform();" >
  76. <label for="sf_first_name" class="w2llabel text">First name: *</label>
  77. <input type="text" name="first_name" class="w2linput text" id="sf_first_name" value="">
  78.  
  79. <label for="sf_last_name" class="w2llabel text">Last name: *</label>
  80. <input type="text" name="last_name" class="w2linput text" id="sf_last_name" value="">
  81.  
  82. <label for="sf_email" class="w2llabel text">Email: *</label>
  83. <input type="text" name="email" class="w2linput text" id="sf_email" value="">
  84.  
  85. <label for="sf_phone" class="w2llabel text">Phone:</label>
  86. <input type="text" name="phone" class="w2linput text" id="sf_phone" value="">
  87.  
  88. <label for="sf_city" class="w2llabel text">City:</label>
  89. <input type="text" name="city" class="w2linput text" id="sf_city" value="">
  90.  
  91. <label for="sf_state" class="w2llabel text">State:</label>
  92. <input type="text" name="state" class="w2linput text" id="sf_state" value="">
  93.  
  94. <label for="sf_country" class="w2llabel text">Country: *</label>
  95. <input type="text" name="country" class="w2linput text" id="sf_country" value="">
  96.  
  97. <label for="sf_description" class="w2llabel textarea">How can we help you?:</label>
  98.  
  99. <textarea name="description" class="w2linput textarea" id="sf_description"></textarea>
  100.  
  101. <input type="submit" value="Submit" class="w2linput submit" name="w2lsubmit">
  102. </form>
Add Comment
Please, Sign In to add comment