0

I have TWO forms on my website.

Is it possible when I submit one of these, it will take form data from a particular field in the other form?

I am using the Recurly system with PHP.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
  • 1
    Maybe you can add `hidden` input fields on your forms, and copy the data onchange or onclick, to ensure you get the results of both forms. – Lan Nov 05 '13 at 09:11
  • Yes it can be done with javascript. You would have to construct two requests with handpicked fields and then send them. – user568109 Nov 05 '13 at 09:12
  • @Lan That's a really good point. I may update the session data with each onChange and then carry this through Recurly. – michaelmcgurk Nov 05 '13 at 09:13
  • 1
    Copying data between fields is fairly trivial with JS, but why would you not just include that particular field in the first form in the first place? – nnnnnn Nov 05 '13 at 09:13
  • Hi @nnnnnn, unfortunately, I'm at the mercy of the 3rd party software, so I can't create custom fields :'( I think I'll go with Lan's suggestion and update a session variable after each change to that form. – michaelmcgurk Nov 05 '13 at 09:15
  • 1
    Remember that if you send 2 or more forms via `document.forms["form1"].submit();`, each request will be aborted except for the last one. So, another solution is send the forms via AJAX calls. – Lan Nov 05 '13 at 09:16
  • Good idea. I think I'll use AJAX calls to a PHP script to create/update the session. Then use the session data once the form has been submitted. – michaelmcgurk Nov 05 '13 at 09:19

2 Answers2

2

You can write your own function.

function submit (){
   document.getElementById("firstform").submit();
   document.getElementById("secondform").submit();
}

You can then make a button that calls this function.

If this doesn't work, try again using ajax. Example

byc
  • 66
  • 10
Mr. Smith
  • 559
  • 1
  • 5
  • 17
1

You can do it with javascript.

For example:

var request =false;

function submit()
{
    var yourobject = document.getElementById("yourobject").value;

    data = "yourobject" + "=" + encodeURIComponent(yourobject);

    request.open("POST", "yourpage.php", true);
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.send(data);
}

And the input:

<input type="button" onclick="submit()" value="Submit" />