Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enter short code [contact] in post or page where you want to use the form
- add_shortcode('contact','custom_contact_form');
- function custom_contact_form(){
- ///Check if the form is submitted
- if (isset($_POST['w2lsubmit'])){
- //Destination email
- $destination="robin@abc.com";
- $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'];
- $sender=$_POST['email'];
- $subject="contact from\r".$sender;
- $headers='From:'. $sender."\r\n".'Reply-To:'.$sender;
- mail($destination,$subject,$message,$headers);
- ?>
- <!--If the form is submitted-->
- Thank you for message
- <?
- }
- else{
- //Before form submission we need to display form
- custom_contact_form_html();
- }
- }
- function custom_contact_form_html(){
- ?>
- <script type="text/javascript">
- function checkform(){
- var x=document.forms["cform"]["first_name"].value;
- if(x==""){
- alert("Please Enter First Name");
- return false;
- }
- var x=document.forms["cform"]["last_name"].value;
- if(x==""){
- alert("Please Enter Last Name");
- return false;
- }
- var x=document.forms["cform"]["email"].value;
- var atpos=x.indexOf("@");
- var dotpos=x.lastIndexOf(".");
- if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
- {
- alert("Not a valid e-mail address");
- return false;
- }
- var x=document.forms["cform"]["country"].value;
- if(x==""){
- alert("Please Enter Country");
- return false;
- }
- }
- </script>
- <form method="post" class="w2llead sidebar" action="<? the_permalink() ?>" name="cform" onsubmit="return checkform();" >
- <label for="sf_first_name" class="w2llabel text">First name: *</label>
- <input type="text" name="first_name" class="w2linput text" id="sf_first_name" value="">
- <label for="sf_last_name" class="w2llabel text">Last name: *</label>
- <input type="text" name="last_name" class="w2linput text" id="sf_last_name" value="">
- <label for="sf_email" class="w2llabel text">Email: *</label>
- <input type="text" name="email" class="w2linput text" id="sf_email" value="">
- <label for="sf_phone" class="w2llabel text">Phone:</label>
- <input type="text" name="phone" class="w2linput text" id="sf_phone" value="">
- <label for="sf_city" class="w2llabel text">City:</label>
- <input type="text" name="city" class="w2linput text" id="sf_city" value="">
- <label for="sf_state" class="w2llabel text">State:</label>
- <input type="text" name="state" class="w2linput text" id="sf_state" value="">
- <label for="sf_country" class="w2llabel text">Country: *</label>
- <input type="text" name="country" class="w2linput text" id="sf_country" value="">
- <label for="sf_description" class="w2llabel textarea">How can we help you?:</label>
- <textarea name="description" class="w2linput textarea" id="sf_description"></textarea>
- <input type="submit" value="Submit" class="w2linput submit" name="w2lsubmit">
- </form>
Add Comment
Please, Sign In to add comment