Reputation: 699
I'm using the newest version of grails (2.4.0). I'm working on applicant form registration. So the header of page is loaded from view/layout/main. On each page of applicant form, I used tag to submit to controller base on the following:
<html>
<body>
<form method='post' id='myform'>
<button type='submit' onclick="submitForm('#myform', ${createlink: action:'applicantInfo1'})">
previous page
</button>
<button type='submit' onclick="submitForm('#myform', ${createlink: action:'applicantInfo3'})">
next page
</button>
</form>
<script type="text/javascript">
function submitForm(id, action){
$(id).attr('action', action);
$(id).submitForm();
}
</script>
</body>
</html>
It works, but now I have to implement the navigation bar (form1 -- form2 -- ... -form 10) and I put it on main page. So it means that I have to remove form from on each page and put form in main:
<form method='post'>
<g:layoutResource/>
</form>
On this one, when I create a button with type=submit onlick='submitForm('myform', action)
(like above), it doesn't work, I just work when I put the action to <form>
Please help me to get through this stack. It's hard to create fiddle demo with it, so I brought the hold code here.
Thanks.
Upvotes: 0
Views: 70
Reputation: 7619
You can use actionSubmit button, there you can specify action
like:
<g:form controller="myController">
<g:actionSubmit value="Previous Page" action="applicantInfo1"/>
<g:actionSubmit value="Next Page" action="applicantInfo3"/>
</g:form>
Upvotes: 0
Reputation: 4128
You can do it by editing the form's action attribute:
onclick="$('form').attr('action', 'some url').submit();return false;"
Upvotes: 1