Note that there are some explanatory texts on larger screens.

plurals
  1. POSending an email via PHP and jquery/ajax from a html page
    primarykey
    data
    text
    <p>I have a very simple question but its been bugging me for quite some time .I have a html contact us page in which I have a simple form which already has validation assigned to it.The form code is : </p> <pre><code> &lt;div class="contact_form"&gt; &lt;form method="post" id="contactForm" name="contactForm" action=""&gt; &lt;fieldset class="contactFieldset"&gt; &lt;ul&gt; &lt;li&gt; &lt;label for="contactName" class="leftLabel"&gt;*Name:&lt;/label&gt; &lt;input type="text" name="contactName" id="contactName" class="contactInput required" value="" /&gt; &lt;/li&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;label for="email" class="leftLabel"&gt;*Email:&lt;/label&gt; &lt;input type="text" id="email" name="email" class="contactInput email required" value="" /&gt; &lt;/li&gt; &lt;span class="simple-success"&gt;I'll be in touch soon&lt;/span&gt; &lt;li&gt; &lt;label for="subject" class="leftLabel"&gt;*Subject:&lt;/label&gt; &lt;input type="text" name="subject" id="subject" class="contactInput required" value="" /&gt; &lt;/li&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;label for="message" class="leftLabel"&gt;*Message:&lt;/label&gt; &lt;textarea rows="10" cols="40" id="message" name="message" class="contactTextarea required"&gt;&lt;/textarea&gt; &lt;/li&gt; &lt;p&gt;&lt;/p&gt; &lt;li&gt; &lt;input type="submit" alt="Submit button" name="submit" class="submit" id="submit"&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>The code which I am using to try and call the php form using ajax is this </p> <pre><code>$(document).ready(function() { //if submit button is clicked $('#submit').click(function () { alert("test i am here"); /*get the email value*/ var email = $("input#email").val(); var name = $("input#contactName").val(); var subject = $("input#subject").val(); var message=$("input#message").val(); alert("email"+email); /* Check if the email is good or bad */ var goodEmail = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.sex)|(\.biz)|(\.aero)|(\.coop)|(\.museum)|(\.name)|(\.pro)|(\.arpa)|(\.asia)|(\.cat)|(\.int)|(\.jobs)|(\.tel)|(\.travel)|(\.xxx)|(\..{2,2}))$)\b/gi); apos=email.indexOf("@");dotpos = email.lastIndexOf(".");lastpos=email.length-1; var badEmail = (apos&lt;1 || dotpos-apos&lt;2 || lastpos-dotpos&lt;2); /*If the email is bad ,display the error message*/ if (email=="" || !goodEmail || badEmail) { $("email").focus(); return false; } var dataString = 'email='+ email + '\n Name='+ name+ '\n Subject='+ subject+ '\n message='+ message; alert (dataString); $.ajax({ type: "POST", url: "mai.php", data: dataString, //Do not cache the page cache: false, success: function(html) { $('.simple-sucess').fadeIn(100).show(); $('.contact_form').fadeOut(100).hide(); $('.simple_error').fadeOut(100).hide(); } }); return false; }); }); </code></pre> <p>The thing is the alert is not even being displayed when I press the submit button..what am I doing wrong here?</p> <p>The validation code is </p> <pre><code>&lt;script type="text/javascript"&gt; jQuery(document).ready(function($){ $("#contactForm").validate(); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload