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: Form submit

  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    160
    Thanks
    71
    Thanked 1 Time in 1 Post

    Form submit

    Hi guys. will try my best to explain my problem, hopefully you can help

    I have a JQuery Mobile app which is like a 3 step form. The header/footer remain the same throughout the app, and I just show/hide the center content as I need too.

    In the first form, the user enters the data, and on submit, I currently do this
    Code:
    $('#form2').submit(function () {
        // Hide the Main content
        hideMain();
    
        // Submit the form
        $.post("forms/requestProcessor.php", form1Var.serialize(), function (data) {
            confirmationVar.text(data);
            hideContentTransition();
            showConfirmation();
        });
        return false;
    });
    Really, this is doing nothing at the moment, infact I have the exact same code for my second forms submit.

    What I really need to do though is when the second form is submit, I get the data from form 1 and form 2, and I send that to an email address. At the moment, my forms are pretty much in the form of
    Code:
    <form id="form2">
      <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">
          <label for="name"> Name </label>
          <input name="name_g" id="name" value="" type="text">
        </fieldset>
      </div>
      <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">
          <label for="phone"> Phone </label>
          <input name="phone_g" id="phone" value="" type="text">
        </fieldset>
      </div>
      <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">
          <label for="email"> Email </label>
          <input name="email_g" id="email" value="" type="text">
        </fieldset>
      </div>
      <div data-role="fieldcontain">
        <input id="submit-btn2" type="submit" value="Submit" data-inline="true"/>
      </div>
    </form>
    So if I remove the Ajax code from my first form, but keep it in my second, how can I retrieve the data from both forms within requestProcessor.php.

    Any information appreciated, and feel free to move if this is more php than ajax.

    Many thanks

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    You could set the information from the first form into hidden fields in the second form and submit all of the data on one submit.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    nick2price (04-04-2013)

  • #3
    Regular Coder
    Join Date
    May 2009
    Posts
    160
    Thanks
    71
    Thanked 1 Time in 1 Post
    Ok, thats understandable. So I have a form like in my original post. Then in my js, I listen for the form submit by doing
    Code:
    $('#form1').submit(function () {
    
        return false;
    });
    But then how would I get the values to form 2? Just out of interest, if I am doing this all in one page (I show/hide the main content) do I need to pass the data to form 2. Wouldnt it be immediately available?

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Not return false - that would prevent the form from submitting.. keep submitting as you do with AJAX, but have the first form submit to the second form, and near the top of the second form code your hidden fields with the same names and populate them from the PHP POST. Then the second form will submit to a processing page that processes form2 data which includes form1 data.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    how about this? never tried it, but in theory, it should work


    Code:
    $('#form2').submit(function () {
        // Hide the Main content
        hideMain();
    
        // Submit the form
        $.post("forms/requestProcessor.php", $("#form1,#form2").serialize(), function (data) {
            confirmationVar.text(data);
            hideContentTransition();
            showConfirmation();
        });
        return false;
    });

  • Users who have thanked DanInMa for this post:

    nick2price (04-04-2013)

  • #6
    Regular Coder
    Join Date
    May 2009
    Posts
    160
    Thanks
    71
    Thanked 1 Time in 1 Post
    Thats more like what I was thinking, just send both forms over. How can I check if this works? Whats the way to get this data printed out in the php file? I am not sure if I just do something like
    Code:
    $myVar = $_POST("#form1");

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I misunderstood the original question. I did not realize that both forms were on the same page.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,297
    Thanks
    10
    Thanked 584 Times in 565 Posts
    in most browsers, you can point elements to different forms using the form attribute, which is now read/write:

    Code:
    $("#form1 [name]").map(function(b,a){
      a.form="form2";
    });
    
    form2.submit();
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    nick2price (04-04-2013)

  • #9
    Regular Coder
    Join Date
    May 2009
    Posts
    160
    Thanks
    71
    Thanked 1 Time in 1 Post
    This is for a mobile site so I better use a safe option. Once I pass the data from both forms to php, as seens in one of the replies, how can I go about retrieving the values in php? From my understanding, it will be a serialized string, so I would need to somehow unserialize it?

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,297
    Thanks
    10
    Thanked 584 Times in 565 Posts
    Quote Originally Posted by nick2price View Post
    This is for a mobile site so I better use a safe option. Once I pass the data from both forms to php, as seens in one of the replies, how can I go about retrieving the values in php? From my understanding, it will be a serialized string, so I would need to somehow unserialize it?
    each input is a property of $_POST.

    so, <input name=lastName /> would be available as $_POST['lastName'].

    you can likely iterate the POST or FORM objects in php to get all the keys, read the php manual page for POST for cut-and-paste code.

    something like
    PHP Code:
     $kv = array();
      foreach (
    $_POST as $key => $value) {
        
    $kv[] = "$key=$value";
      } 
    Last edited by rnd me; 04-04-2013 at 08:47 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #11
    New Coder
    Join Date
    Apr 2013
    Posts
    39
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by rnd me View Post
    each input is a property of $_POST.

    so, <input name=lastName /> would be available as $_POST['lastName'].

    you can likely iterate the POST or FORM objects in php to get all the keys, read the php manual page for POST for cut-and-paste code.

    something like
    PHP Code:
     $kv = array();
      foreach (
    $_POST as $key => $value) {
        
    $kv[] = "$key=$value";
      } 
    i will advice you use jquery to hide the first form on user submit and display the second form which you will pass to you php script and use the code above to collect the variables


  •  

    Posting Permissions

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