Welcome Guest, Not a member yet? Register   Sign In
Invoke Form submit automatically from within controller
#2

[eluser]Akinzekeel[/eluser]
If I understood you correctly, you could do it like this:
- Post your stuff to the controller via AJAX (jQuery javascript Framework offers easy handling of this)
- When the AJAX request is complete (i.e. when your data was inserted) run a javascript function which submits the form

Here's an example with jQuery. It will show the order summary and when your customer clicks "Place order" it will trigger your controller function which does some database insert. After that request is completed it will submit the actual <form> to a different controller function.

Code:
<script>
function doInsert() {
$.post("http://example.com/controller/function/", {myData1: "I am ready!", myData2: "some more data!"}, function(a,b,c) {
// this will execute AFTER your controller has finished execution and has delivered some output
document.myFormName.submit(); // submit the form
});
}
</script>

<p>Your order summery here...</p>

&lt;button onclick="doInsert()">Place order!</button>
&lt;form method="post" action="http://example.com/controller/myPaymentFunction" name="myFormName"&gt;
&lt;input type="hidden" name="submitdata" value="some data for 2nd POST"&gt;
&lt;/form&gt;


Messages In This Thread
Invoke Form submit automatically from within controller - by El Forum - 03-23-2011, 12:17 AM
Invoke Form submit automatically from within controller - by El Forum - 03-23-2011, 07:23 AM
Invoke Form submit automatically from within controller - by El Forum - 03-23-2011, 10:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB