I need to have a form execute two scripts so that means two different actions from the same form. I've tried some javascripts that use form.submit() from an onClick action on a submit button. But one of the two actions is an ASPX script that goes to Dynamics CRM. Any suggestions?
+3
A:
Maybe the form could have only one action that would forward the request to the second action, once it has finished its operation
aletzo
2010-08-04 18:09:35
Definitely agree. `<form action="action1.php" method="post">`, do your thang on action1.php, and then send the data over to action2.php.
hookedonwinter
2010-08-04 18:12:05
+1 — doing this on the server instead of trying to get the client to do things forms were not designed for is the correct solution. The forwarding can (and often should) be done entirely internally with a simple controller pushing the data off to two routines to process it and then returning a single result to the browser.
David Dorward
2010-08-04 18:12:33
I have no access to the first action or I would take hookedonwinter's suggestion. Could someone point me in the right direction with some AJAX?
2010-08-04 18:14:40
Do you understand jquery ajax calls? (asking because the solution will either be detailed or vague depending)
hookedonwinter
2010-08-04 18:16:40
no I am a noob!
2010-08-04 18:22:26
@shummel sorry for not reading your question thoroughly from the start. I should have seen the aspx part and not suggested my original suggestion.
hookedonwinter
2010-08-04 18:25:22
+1
A:
Using jQuery, you could interrupt the form submission and do your own thing before it actually submit.
Example using jquery's ajax post:
$( 'form' ).submit( function(){
$.post(
'action2.php', // url of php
{ // data to send
data1:'bob',
data2:'denver'
}
)
})
hookedonwinter
2010-08-04 18:21:37
@shummel this won't just "plug-n-play". You'll need to include jquery first, etc. Read up on jQuery, it's ridiculously useful.
hookedonwinter
2010-08-04 18:23:25
A:
Could you not have an intermediate script, that dispatches the info. to the second script? For example (submit.php
):
<?php
if (isset($_POST['action_1'])) {
// send to script 1
}
else if ($_POST['action_2']) {
// send to script 2
}
else {
// friendly error handling here
}
?>
And your form's mark-up...
<form action="submit.php" method="post">
<input type="submit" name="action_1" value="Action 1" />
<input type="submit" name="action_2" value="Action 2" />
</form>
Martin Bean
2010-08-04 19:10:23