Web Analytics Made Easy -
StatCounter PHP Form - CodingForum

Announcement

Collapse
No announcement yet.

PHP Form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Form

    Hi,

    I have built this form following the instructions here:


    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
    Please post the code your having trouble with
    Been a sign maker for 8 years. My business:
    American Made Signs

    Comment


    • #3
      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 [email protected]):

      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 = "[email protected]" ; // 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.

      Comment


      • #4
        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.
        Been a sign maker for 8 years. My business:
        American Made Signs

        Comment


        • #5
          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>

          Comment


          • #6
            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.

            Comment


            • #7
              Ok I don't know the first thing about Ajax, it's not one of my languages, so I won't be much help.
              Been a sign maker for 8 years. My business:
              American Made Signs

              Comment


              • #8
                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.

                Comment


                • #9
                  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?

                  Comment


                  • #10
                    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.

                    Comment


                    • #11
                      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!

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎