www.webdeveloper.com
Results 1 to 6 of 6

Thread: Form throwing error messages

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Unhappy Form throwing error messages

    When I submit my form, I get an the "You must write a message" echo from the PHP code, and I also get the error message from the ajax. I don't need the PHP echo messages because I have the ajax messages. Can't figure out the problem.

    I would like to only use the ajax messages.

    Here is the ajax:
    Code:
    $(function(){
    
    $("#btnSend").click(function(){
    
    $.ajax({type:'POST', url: './php/mailer.php', data:$('#frmContact').serialize(), success: function(response) {
    $("#spanMessage").html('Please Wait...');
    
    
    	 if(parseInt(response)>1)
    	   {
    		 $("#spanMessage").html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button><strong>Well done!</strong> Your message has been sent.</div>');
    	   }
    	   else{
    		 alert(response);
    		 $("#spanMessage").html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button><strong>Error! </strong> Somthing Wrong</div>');
    	   }
    	   
    		 
    }});
    
    
    });
    Here is the PHP:
    PHP Code:
    <?php session_start();
    if(isset(
    $_POST['Submit'])) {
    $youremail 'wjordan1987@gmail.com';
    $fromsubject 'Test Email';
    $txtName $_POST['txtName'];
    $txtEmail $_POST['txtEmail'];
    $txtSubject $_POST['txtSubject']; 
    $txtText $_POST['txtText']; 
    $to $youremail
    $mailsubject 'Masage recived from'.$fromsubject.' Contact Page';
    $body $fromsubject.'

    The person that contacted you is  '
    .$txtName.'
     E-mail: '
    .$txtEmail.'

     Message: 
     '
    .$txtText.'

    |---------END MESSAGE----------|'

    echo 
    "Thank you fo your feedback."
                                
    mail($to$subject$body);
     } else { 
    echo 
    "You must write a message."
    }
    ?>
    Here is the HTML form:
    HTML Code:
    <form action="" method="post" id="frmContact">
    <h5>Whats your Name?</h5>
    <input name="txtName" type="text" class="txbx" value="Name" /><br />
    <h5>Whats your Email?</h5>
    <input name="txtEmail" type="text" class="txbx" value="Email" /><br />
    <h5>Email Subject?</h5>
    <input name="txtSubject" type="text" class="txbx" value="Subject" /><br />
    <div class="erabox">
    <h5>Message to us</h5>
    <textarea name="txtText" cols="" rows="" class="txbx era" value="Message" ></textarea><br />
    <input name="Submit" type="button" class="sendbtn" value="Send Message" align="left" id="btnSend"/>
    </form>

  2. #2
    Join Date
    Nov 2012
    Location
    Jakarta
    Posts
    42
    In the PHP code, just comment the line
    Code:
    echo "You must write a message.";
    .

    By commenting, you simply put "//" at the beginning of the line.

    Or, you can delete the line alltogether.

  3. #3
    Join Date
    May 2013
    Posts
    2
    I dont think the commenting the line makes any difference? error is still poping.

  4. #4
    Join Date
    Mar 2013
    Location
    Iasi, Romania
    Posts
    53
    try to change the line
    Code:
    <input name="Submit" type="button" class="sendbtn" value="Send Message" align="left" id="btnSend"/>
    to
    Code:
    <input name="Submit" type="submit" class="sendbtn" value="Send Message" align="left" id="btnSend"/>
    Last edited by ssdog; 05-21-2013 at 03:31 AM.

  5. #5
    Join Date
    Mar 2013
    Location
    Iasi, Romania
    Posts
    53
    I have tested the code and it worked for me
    And one more thing: why don't you use SMTP Mailer?...it's more reliable and a bit faster
    Last edited by ssdog; 05-21-2013 at 05:46 AM.

  6. #6
    Join Date
    May 2013
    Posts
    2
    the code is live at http://ssservices.co/contact.html it is not working for me... can you suggest appropriate.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles