views:

692

answers:

3

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>
A: 

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"&gt;
  <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>
Sarfraz
That'd be neat if I could modify the html for the form, but alas, I cannot...
SnarkytoSnarkers
@SnarkytoSnarkers: just replace your step 3 form with the one i have written with bold text **Use** and lastly add the script i have written above at the end of your file. Thanks
Sarfraz
I'm not sure how else to explain that I can't modify the html for this page, but to say, I can't modify the html for this page. Otherwise, I'd do exactly as you say... But, again, I can't modify the html for this page.
SnarkytoSnarkers
+1  A: 

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.

Koobz
I'm really not being shady... I promise. This is *our* agreement form, that the third party has included in the overall process, but never provided a way to get rid of it. It winds up being a redundant step because they have to agree to TOS during registration. They won't even get to this process unless they register. It's an oversight by the 3rd party developers, and while they're "working on a solution", we still need it to function the way we want...
SnarkytoSnarkers
A: 

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.

orip