title: Form Submit Javascript PHP not working, help please?
body: <p>I am having a hard time getting my form to work. </p>
  
  <p>Can anyone take a look at this and tell me why nothing happens when I try it in a live environment? I managed to get the form to submit using "action" in the form tag whilst ditching the javascript altogether, with the PHP returning both Error and success depending on whether I filled out all fields and the email was successfully received.</p>
  
  <p>However I want to use the javascript method so that I can prevent a page reload and use alert messages as this form will be used inside a packaged mobile app. </p>
  
  <p>Any help is much appreciated. </p>
  
  <pre><code>    &lt;form  method="post" name="form1" id="form1"&gt;
        &lt;label for="textfield"&gt;Text Field:&lt;/label&gt;
        &lt;input name="FirstName" type="text" id="FirstName"&gt;
        &lt;label for="textfield2"&gt;Text Field:&lt;/label&gt;
        &lt;input name="LastName" type="text"  id="LastName"&gt;
        &lt;label for="textfield3"&gt;Text Field:&lt;/label&gt;
        &lt;input name="Email" t ype="text"id="Email"&gt;
        &lt;label for="textfield4"&gt;Text Field:&lt;/label&gt;
        &lt;input name="MessageText" type="text"  id="MessageText"&gt;
  
      &lt;input type="button" onclick="submit()" value="submit contact"/&gt;
     &lt;/form&gt;
  
      &lt;script&gt;
      $(document).ready(function(){
        event.preventDefault();
        $("form").submit(function(){
          $.post('http://************/requestform.php', {
  
  
  
          FirstName: $('#FirstName_input').val(),
          LastName: $('#LastName_input').val(),
          Email: $('#Email_input').val(),
          MessageText: $('#MessageText_input').val()
  
  
  
          }, function (html) {
  
              var response=html;
  
  
               if (response=="success") {
                 alert("Message sent!"); 
              } else {
  
  
                 alert("Sorry please fill all fields!"); 
              return false;
          }
         });
  
        });
      });
  </code></pre>
  
  <p>and the PHP part</p>
  
  <pre><code>    &lt;?php
  
  
       $FirstName=$_POST["FirstName"];
       $LastName=$_POST["LastName"];
       $Email=$_POST["Email"];
       $MessageText=$_POST["MessageText"];
       $Headers = "From:" . $Email;
  
  
       if(
       $FirstName=="" ||
       $LastName=="" ||
       $Email=="" ||
       $MessageText==""
       ) {
           echo "Error";
       } else {
           mail("*******@gmail.com","mobile app message",$MessageText, $Headers);
           echo "success";
       }
   ?&gt;
  </code></pre>