Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hello everyone,

    The PHP script I have that receives POST values from a jQuery .ajax() call. I am trying to debug and find out why I'm not getting any result echoed back to the jQuery script, and thus reflect a success or failure message.

    This is the confirmform.php file
    PHP Code:
    <?php
        $instance 
    = new CheckForm;
        
    $instance -> checkSubmission();
        
        class 
    CheckForm
        
    {
            public function 
    checkSubmission()
            {    
                
    $response = array("validation" => " ""message" => " ");    
                if (
    $_POST['country'] != "Select Country")
                {
                    if (isset(
    $_POST['confirmEmail']) && isset($_POST['name']))
                    {
                        
    $origEmail $_POST['origEmail'];
                        
    $confirmEmail $_POST['confirmEmail'];
                        if (
    $origEmail == $confirmEmail)
                        {
                            
    $name htmlspecialchars($_POST['name']);
                            
    $ageRange $_POST['age'];
                            
    $country $_POST['country'];
                            
                            require_once(
    "categoryfinder.php");
                            
    $categoryFinder = new CategoryFinder;
                            
    $category $categoryFinder -> getCategory();
                            
                            require_once(
    'databasewriter.php');
                            
    $dbWriter = new DatabaseWriter;
                            
    $dbWriter -> writeUserToDatabase($confirmEmail$name$ageRange$country$category);
                            
    $response = array("validation" => "pass""message" => "Thanks for joining the e-mail list, " $name ", under the e-mail address, " $confirmEmail ".");
                        } else {
                            
    $response = array("validation" => "fail""message" => "E-mail addresses don't match.");
                            die();
                        }
                    } else {
                        if (!isset(
    $_POST['confirmemail'])){
                            
    $response = array("validation" => "fail""message" => "Confirmation e-mail not entered.");
                        } elseif (!isset(
    $_POST['name'])) {    
                            
    $response = array("validation" => "fail""message" => "Please enter a name.");
                        }
                    }
                } else {
                    
    $response = array("validation" => "fail""message" => "Please select a country.");
                }
                echo 
    json_encode($response);
            }
        }
    ?>
    The jQuery .ajax() call:
    Code:
    $("#submissionform").submit(function(e){
                var origEmail = $('#go').val();
                var confirmEmail = $("#confirmemail").val();
                var name = $("#name").val();
                var age = $("#age").val();
                var country = $("#country").val();
                alert(origEmail);
                
                e.preventDefault();
            
                $.ajax({
                  type: "POST",
                  dataType: 'json',
                  cache: false,
                  url: "Scripts/confirmform.php",
                  data: { origEmail: origEmail,
                        confirmEmail: confirmEmail,
                        name: name,
                        age: age,
                        country: country },
                  success: function(data){
                      console.log(data);
                      alert(data);
                      testSecondResults(data);
                  }
                });
            });
          });
    The 2nd form markup:
    HTML Code:
            <div id="submissionform"> <!-- begin 2nd form markup -->
        <form name="form2" method="post" action="Scripts/confirmform.php">
        <div>
          <label for="confirmemail" class="fixedwidth">Confirm your e-mail:<span>*</span></label>
          <input type="text" name="confirmemail" id="confirmemail" value="" maxlength="60" class="inputwidth"/>
        </div>
        <div>
          <label for="name" class="fixedwidth">Enter your name:<span>*</span></label>
          <input type="text" name="name" id="name" value="" maxlength="60" class="inputwidth"/>
        </div>
        <div>
          <label for="age" class="fixedwidth">Select your age range:</label>
          <select name="age" id="age" class="inputwidth">
             <option selected="selected">18&ndash;35</option>
             <option>36&ndash;55</option>
             <option>55+</option>
             <option>17 or younger</option>
          </select>
        </div>
        <div>
          <label for="country" class="fixedwidth">Select your country:<span>*</span></label>
          <select name="country" id="country" class="inputwidth">
              <option selected="selected">Select Country</option>
              <option>United States</option>
              <option>United Kingdom</option>
              <option>Canada</option>
              <option>Australia</option>
              <option>Russia</option>
              <option>Brazil</option>
              <option>Somewhere else</option>
          </select>
         </div>
         <p id="errormessage">&nbsp;</p>
          <input type="submit" value="Sign Me Up!" class="formsubmitbutton" id="finalsubmit"/>
          <input type="button" value="Cancel" class="formsubmitbutton" onclick="backToHomePage()"/>
        </form>
      </div>
        </div>
    In Firebug, I am seeing this error:
    Error: Permission denied to access property 'toString'




    slice.call( docElem.childNodes, 0 )[0].nodeType;

    jQuery.js(line3811)
    This is a screenshot of what it looks like after the first form has been submitted.
    This is my website.

    Thanks for your help! :nerd:

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    How do you get to the part about the form when viewing the website you are showing us?


  4. #3
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Well, it won't work unless I upload the PHP I have that gets it to that position. I just read that it's bad practice to upload PHP files when you're in the middle of a project.

    Should I upload my files?

    You would get that form to show/activate by submitting a valid e-mail in the red-orange e-mail submission box on the lower-right side.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    You have to upload the files ... how else will it work? I've never heard of such a thing as not uploading files in the middle of a project. Upload everything to get it at the point where we can see it (working or not working).


  6. #5
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Okay, now the files are uploaded and you can interact with that bottom e-mail submission box to get the second form to come up.

  7. #6
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Oops, I did find some errors. I'm going to need to try-catch the DatabaseWriter object somehow.

    Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\xampp\htdocs\Scripts\databasewriter.php on line 7

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. ' in C:\xampp\htdocs\Scripts\databasewriter.php:7 Stack trace: #0 C:\xampp\htdocs\Scripts\databasewriter.php(7): PDO->__construct('mysql:host=worl...', 'worldreviewgrou...', 'PASSWORD') #1 C:\xampp\htdocs\Scripts\confirmform.php(28): DatabaseWriter->writeUserToDatabase('etidd88@ymail.c...', 'Tyler', '18???35', 'United States', '') #2 C:\xampp\htdocs\Scripts\confirmform.php(3): CheckForm->checkSubmission() #3 {main} thrown in C:\xampp\htdocs\Scripts\databasewriter.php on line 7

  8. #7
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    I fixed the fatal error by adding in the following changes:

    PHP Code:
    try{
                                require_once(
    'databasewriter.php');
                                
    $dbWriter = new DatabaseWriter;
                                
    $dbWriter -> writeUserToDatabase($confirmEmail$name$ageRange$country$category);
                            } catch (
    PDOException $e) {
                                
    $response = array("validation" => "pass""message" => "Thanks for joining the e-mail list, " $name ", under the e-mail address, " $confirmEmail ".""database" => "fail");
                            } 
    I still can't figure out the second one, and the page just sits there on form submission.

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Here's the way I would approach this problem.

    I'm not sure if you got that script from somewhere online?

    To test and make the mailing list form operational ...
    I would create a plain simple HTML page and only have the "join mailing list" thing on the page. No other scripts, graphics, etc. Just the "join mailing list" script. I have a hunch that what you're doing is harder (more scripting) than it needs to be. Get it working all by itself on a "test page".

    Although it's your site not mine, and this isn't a place to critique, I would use an already created structure for my site, such as WordPress or Joomla. There is going to be so much involved beyond your mailing list script problems. Just the security issues alone. I can't imagine creating a site like that from scratch.
    Tyler Smith likes this.


  10. #9
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hm... those are definitely things to consider.


Remove Ads

Posting Permissions

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

Search tags for this page

jquery ajax second submit

,
submit second form after first form processes php
Click on a term to search for related topics.
All times are GMT -6. The time now is 12:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com