my form has got two buttons ... both for entirely different purpose.. so there is a necessity to have sep开发者_StackOverflow中文版arate actions ... Is it possible? if not what is the best possible solution to deal with such problem... Thanks is advance
The <g:actionSubmit>
tag allows you to have multiple submit buttons in a single form.
<g:form controller="test">
<g:actionSubmit value="Submit to success" action="success"/>
<g:actionSubmit value="Submit to delete" action="delete"/>
</g:form>
You can use <g:actionSubmit/>
buttons to have a single grails form go to different actions.
<g:form method="post">
...
<g:actionSubmit action="oneAction" value="One Action"/>
<g:actionSubmit action="anotherAction" value="Another Action"/>
</g:form>
Clicking "One Action" would be handled by the oneAction
action of the current controller; clicking "Another Action" would be handled by the anotherAction
action of the current controller.
A single form can have only one action.
You can change that action, dynamically, using JavaScript, but that adds a dependancy on JS.
Better is to have the form submit to a single URL and then do something along the lines of (pseudo code):
if (submit is foo) {
process_form_with_foo_class()
} elseif (submit is bar) {
process_form_with_bar_class()
} else {
// Form was submitted without using a submit button
// e.g. with enter, or JS.
process_form_with_foo_class() // Let's use foo as the default
}
精彩评论