Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Orlando, FL
    Thanked 8 Times in 8 Posts

    Question How would I obtain the post value from a form submitted on previous page?

    I couldn't decide which thread was most suitable for this question, seeing as how I'm not sure if it's a javascript, jQuery, JSON, or AJAX issue, so I apologize if this is in the wrong place.

    I have a form on a page named build_cake.php. It is only there to utilize the POST method. I stringified an object with JSON-js and set it to the value of the input from the aforementioned form. *See code below*

    var jsonText = JSON.stringify(cake); \\stringify the object titled 'cake' and store it to the variable 'jsonText'
    var myForm = "<form id='temporary_form' action='verify_cake.php' method='POST'><input id='passedObject' name='passedObject' value='" + jsonText + "' /></form>"; \\create the form and set the value= jsonText
    $(myForm).submit(); \\submit form
    Now, I know it works because I can get the string with PHP on the 'verify_cake.php' page using the POST method. However, is there a way for me to get this string with either javascript, jQuery, JSON, or AJAX? If so, could someone point me in the right direction? I know there is a POST method for AJAX and jQuery, but I was under the impression that is to send data to another page while staying on your current page. I need to take this cake object with me to a new page.

  2. #2
    Senior Coder
    Join Date
    Sep 2010
    Thanked 275 Times in 275 Posts
    Since you're using PHP you can always set it as a$_SESSION variable and if it isset on the page your're going to, get it from there.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.

    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  3. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 626 Times in 605 Posts
    you have to echo the POST data back to JS from PHP. you can use echo json_encode($thePostDataObject) in php to turn the object into JSON, which you can assign to a variable in a <script> block to reach from JS.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


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