tags:

views:

57

answers:

3

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
Definitely agree. `<form action="action1.php" method="post">`, do your thang on action1.php, and then send the data over to action2.php.
hookedonwinter
+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
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?
Do you understand jquery ajax calls? (asking because the solution will either be detailed or vague depending)
hookedonwinter
no I am a noob!
@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
+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
@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
Thanks, hookedonwinter. Hopefully I can get this going.
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