jquery question… a way to automatically submit a form and move to the next step?

By : Watts
Source: Stackoverflow.com
Question!

Basically, I have a process that is broken out into 4 forms (thus, 4 urls), but I'd like to bypass the third one completely. I can't really get to the code itself as it's from a third party provider and not open-source. What I was hoping to do was to use jquery to automatically fill out and submit the form as soon as the user gets to that third step, and do it so quickly / automatically, that the page itself is virtually unseen... Is something like that doable?

So, here's a simplified breakdown of the process...

STEP ONE: http://sample.com/step1.aspx

<form name="step1">
<input type="text" name="stepone" value="" />
<input type="submit" name="steponesubmit" value="Submit" />
</form>

STEP TWO: http://sample.com/step2.aspx
<form name="step2">
<input type="text" name="steptwo" value="" />
<input type="submit" name="steptwosubmit" value="Submit" />
</form>


STEP THREE: http://sample.com/step3.aspx
(This is the one I'd like to fill out and submit automatically... 
 Basically, I want to mimic the user having pressed the "Agree" button)
<form name="step3">
<input type="submit" name="stepthreeagree" value="Agree" />
<input type="submit" name="stepthreedisagree" value="Disagree" />
</form>

STEP FOUR: http://sample.com/step4.aspx
<form name="step4">
<input type="text" name="stepfour" value="" />
<input type="submit" name="stepfoursubmit" value="Submit" />
</form>
By : Watts


Answers
You can jQuery('input[name=stepthreeagree]').trigger('click'). If the form DOM is available.

Or you can try posting/getting to the location with the appropriate data. I.E

jQuery.post('blahblah.html',{ stepthreeagree: 'Agree' })

Often times though, these multi-step forms daisy chain their data (either through sessions or hidden inputs) so this solution might be insufficient.

Just a comment: it kind of sounds like you're doing something sketchy. There's a good theoretical question here, but why are you trying to bypass someone's agreement form?

Sarfraz: multiple submit buttons are valid. The one that gets clicked is the one whose value is submitted. Not sure if this is spec, or just the case for PHP.

By : Koobz


First of all don't use two submit buttons for a single form eg:

Don't Use:

<form name="step3">
  <input type="submit" name="stepthreeagree" value="Agree" />
  <input type="submit" name="stepthreedisagree" value="Disagree" />
</form>

Use:

<form name="step3" action="http://sample.com/step3.aspx">
  <input type="radio" name="agree" value="agree" checked="checked" />
  <input type="radio" name="agree" value="disagree" />
  <input type="submit" name="stepthreeagree" value="Submit" />
</form>

Now since the agree button is already checked, you can auto-submit the form like this:

<script>
window.onload = function()
{
  document.step3.submit();
};
</script>
By : Sarfraz


Can you add JavaScript to all the pages?

If so, in step2.aspx you can override the submission of the form, submit it in AJAX, then submit the third from regularly (e.g. add the <form> to the page, submit it with jQuery).

This way step3.aspx won't even flicker.

Even if there's some sort of CSRF protection you can grep the CSRF protection field from the response to the AJAX submission.

By : orip


This video can help you solving your question :)
By: admin