Home Grails 2.x submit form with additional parameters
Reply: 1

Grails 2.x submit form with additional parameters

Muhammad Ramahy
Muhammad Ramahy Published in 2018-01-01 18:16:58Z

I am a newbie to grails I want to make a form that submit form params plus other params in a gsp

the gsp looks like this:

<g:form url="action:'myAction',controller:'myTerms', params:[params: params, myCheckbox: myCheckbox]">
                    <p><g:checkBox id="myCheckbox" name="myCheckbox" value="true" checked="checked"/><g:message code="terms.agree"/><a style="color: #ed1c24" href="/xyz"><g:message code="terms.termsConditions"/></a><g:message code="terms.ofService"/></p>
                    <g:actionSubmit value="Subscribe" />

it should submit to controller named MyTermsController to the action below:

def myAction(){
        if(/*condition 1*/){
                if (/*condition 2*/) {
                    //more code
            }catch (AlreadyPurchasedException ape){
                redirect(controller: "controllerA", action: "showXhtml", params:params)
            redirect(controller: "controllerB", action: "handlePaymentXhtml", params: params)
        }else if(/*condition 3*/){
            redirect(controller:"controllerC", action:"purchaseXhtml", params:params)

What I am trying to do is to submit a form with params without using javascript.

now every time I press submit, the application is redirected to the error page telling me that the page is not found.

can anyone tell me what am I missing/doing wrong?

Mike W
Mike W Reply to 2018-01-01 19:46:47Z

I think the issue is with your syntax in the form url attribute, you could try the following approach:

<g:form controller="mTerms" action="myAction">

Also, you don't need to specifically submit params or myCheckbox as they'll be submitted automatically.

If you wanted to submit additional values you could use the spread operator like this:

<g:form controller="mTerms" action="myAction" params="[aKey: 'aValue', *:params]">

Finally I think you need to use g:submitButton rather that g:actionSubmit

<g:submitButton value="Subscribe" name="subscribe" />
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.35386 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO