Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: PHP Form

  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP Form

    Hi,

    I have built this form following the instructions here:
    http://youhack.me/2010/07/22/create-...-3-and-jquery/

    The validation of the form works fine but when I fill the form in and press the 'Send' button, nothing happens at all. I've checked the path to the php file and it seems fine and my web host supports php.

    I've followed the tutorial and used the files they supplied, so not sure what I'm doing wrong.

    Any help would be massively appreciated.

    Cheers,
    Jimmy

  • #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,463
    Thanks
    71
    Thanked 103 Times in 102 Posts
    Please post the code your having trouble with

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    This is the code for my form:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
      
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
     
     
    <head> 
     
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
     
    <title>Testing</title> 
     
    	<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script> 
    	<script src="js/jquery-ui-1.8.12.custom.min.js" type="text/javascript"></script> 
       	<script src="js/SimpleNavBarScripts.js" language="JavaScript" type="text/javascript"></script> 
       	<script src="js/jquery.validationEngine-en.js" type="text/javascript"></script> 
    	<script src="js/jquery.validationEngine.js" type="text/javascript"></script> 
     
        <!-- Links to the CSS for the Contact Forms --> 
        <link rel="stylesheet" href="CSS/formstyle.css" type="text/css" media="all" /> 
    	<link rel="stylesheet" href="CSS/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" /> 
        <link rel="stylesheet" href="CSS/template.css" type="text/css" media="screen" title="no title" charset="utf-8" /> 
        <!-- Link to the main CSS used for Website. --> 
    	<link href="CSS/style.css" rel="stylesheet" type="text/css" /> 
        <!-- Link to styles used for Navigation Bar --> 
        <link href="CSS/SimpleNavBarStyles.css" rel="stylesheet" type="text/css" /> 
     
         		<script type="text/javascript"> 
    		    $(document).ready(function () {
                        // SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
    		        $("#form1").validationEngine({
    		            ajaxSubmit: true,
    		            ajaxSubmitFile: "ajaxSubmit.php",
    		            ajaxSubmitMessage: "Thank you, We will contact you soon !",
    		            success :  false,
    		            failure: function () { }
    		        })
     
                 });
    		</script> 
            
            		
            
    </head> 
     
    <body id="Home"> 
     
     
    <div id="wrapper"> 
      <div id="form-div"> 
        <form class="form" id="form1"> 
          <p class="name"> 
            <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] text-input" id="name" value="" /> 
            <label for="name">Name</label> 
          </p> 
          <p class="email"> 
            <input name="email" type="text" class="validate[required,custom[email]] text-input" id="email" value="" /> 
            <label for="email">E-mail</label> 
          </p> 
          <p class="web"> 
            <input type="text" name="web" id="web" /> 
            <label for="web">Website</label> 
          </p> 
          <p class="text"> 
            <textarea name="text" class="validate[required,length[6,300]] text-input" id="comment"></textarea> 
          </p> 
          <p class="submit"> 
            <input type="submit" value="Send" /> 
          </p> 
        </form> 
      </div> 
    </div> 
     
    </body> 
     
    </html>

    and this is the ajaxSubmit.php code (i put my email address in place of testing@testing.co.uk):

    Code:
    //Code Updated on 18 Feb 2011
    
    
    
    $name = $_POST['name']; // contain name of person
    
    $email = $_POST['email']; // Email address of sender
    
    $web = $_POST['web']; // Your website URL
    
    $body = $_POST['text']; // Your message
    
    $receiver = "testing@testing.co.uk" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to
    
    if (!empty($name) & !empty($email) && !empty($body)) {
        
    	$body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
    	
    	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
        
    	if ($send) {
            
    		echo 'true'; //if everything is ok,always return true , else ajax submission won't work
        
    	}
    
    
    
    }
    There are several javascript files to validate etc, but i wont bother putting the code up for them unless you need them. All the source files can be downloaded from the link in my original post too.

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,463
    Thanks
    71
    Thanked 103 Times in 102 Posts
    Really belongs in the JS/Ajax forum, but pay attention to this line:

    PHP Code:
    <form class="form" id="form1"
    Unless it has the url in your DIV somehow, it won't work, it doesn't have a target.

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sorry myfat, what do you mean? complete newbie to this.

    I presume the script at the top called the form1:
    Code:
    <script type="text/javascript"> 
    		    $(document).ready(function () {
                        // SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
    		        $("#form1").validationEngine({
    		            ajaxSubmit: true,
    		            ajaxSubmitFile: "ajaxSubmit.php",
    		            ajaxSubmitMessage: "Thank you, We will contact you soon !",
    		            success :  false,
    		            failure: function () { }
    		        })
     
                 });
    		</script>

  • #6
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    It appears the script Jimmy is using submits via AJAX, myfat. As a result the form action won't have any bearing.

    The code seems to be congruent with what it needs to be. There are a few issues that could be causing this.

    Here's what I think you should do to bug test. Stop at each step to observe your results:

    - First, make sure that the "ajaxSubmit.php" page is in the exact same directory as your HTML page. You have added no path (i.e: public_html/my_dir/ajaxSubmit.php"), so the server assumes it's in the same folder.

    - Second, if it's in the same directory, let's check to see if the script thinks it's succeeding. Add the following code directly AFTER your line success : , thus DELETING false:

    Code:
    function(){ alert( "Success Pinged" ); }
    If you see the alert dialog after you run the script, the plugin is working - you're just not getting the emails.

    - Third, test the PHP page by taking AJAX out of the component. Temporarily remove your plugin's code, lines 26 to 36.

    Now, change your form's head from:
    Code:
    <form class="form" id="form1">
    to

    Code:
    <form action="ajaxSubmit.php" class="form" id="form1">
    Submit your forum, and observe what the PHP tells you. Then report that back.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • Users who have thanked ShaneC for this post:

    Jimmy1981 (08-28-2011)

  • #7
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,463
    Thanks
    71
    Thanked 103 Times in 102 Posts
    Ok I don't know the first thing about Ajax, it's not one of my languages, so I won't be much help.

  • #8
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hi Shane,

    my ajaxSubmit.php is definately in the same place as the html page.

    I added the line you said so my code looked like this:

    Code:
         		<script type="text/javascript">
    		    $(document).ready(function () {
                        // SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
    		        $("#form1").validationEngine({
    		            ajaxSubmit: true,
    		            ajaxSubmitFile: "ajaxSubmit.php",
    		            ajaxSubmitMessage: "Thank you, We will contact you soon !",
    		            success :  function(){ alert( "Success Pinged" ); },
    		            failure: function () { }
    		        })
    
                 });
    		</script>
    And i got nothing, still no action when the Send button is sent.

    The next step:

    I took out the script code at the top, added the new line as you said and when I press submit it opens the ajaxSubmit.php code in the browser the form was in, no emails sent.

  • #9
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    OK, I figured the ajaxsubmit.php should be wrapped in php code tags but it wasn't so I've added them, I also saw inthe script at the top the guy had a comment:

    Code:
    	// SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() },
    so i replace that line and now I have this:
    Code:
            		<script> 
    		$(document).ready(function() {
    			
    			
    			
    			// SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
    			$("#form1").validationEngine({
    				ajaxSubmit: true,
    					ajaxSubmitFile: "ajaxSubmit.php",
    					ajaxSubmitMessage: "Thank you, We will contact you soon !",
    				 	success : function() { callSuccessFunction() }, 
    					failure : function() {}
    			})
    			
     
    		
    		});
    		</script>
    The emails now send but i get an error message that says:

    This is a debug mode, you got a problem with your form, it will try to help you, refresh when you think you nailed down the problem
    you are not going into the success fonction and jsonValidateReturn return nothing


    I guess this isnt really a PHP problem now though is it?

  • #10
    Codeasaurus Rex
    Join Date
    Jun 2008
    Location
    Redmond, WA
    Posts
    659
    Thanks
    31
    Thanked 100 Times in 94 Posts
    Try replacing success : function() { callSuccessFunction() } with success : function() { alert( "Application has succeeded!" ); }.

    If you see an alert box pop up saying Application has succeeded and the debug statement is gone you should be good. My guess is that when he says "callSuccessFunction()" that's to tell you to call your own success function, not necessarily that the specific function exists. I could be mistaken.
    Unless otherwise stated, any code posted is most likely untested and may contain syntax errors.
    My posts, comments, code, and suggestions reflect only my personal views.
    Web Portfolio and Code Snippets: http://shanechism.com

  • #11
    New Coder
    Join Date
    May 2011
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, for all the help. managed to sort it out, not sure what was wrong with it tbh, but your help pointed me in the right direction!


  •  

    Posting Permissions

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