How can I set the request parameters of method post int routes file in Play!2.0

167 views
Skip to first unread message

zoowii

unread,
May 29, 2012, 12:51:50 PM5/29/12
to play-fr...@googlegroups.com
I know how to set parameters of http method get if routes, but how to set the parameters of http method post?

Waitting...

sun

unread,
May 30, 2012, 11:01:46 AM5/30/12
to play-framework
You do not specify these parameters in your routes, you would only do
it for GET parameters.
Just bind the parameters from the request to a form in your controller
and your done.

Zihao Yu

unread,
May 31, 2012, 2:39:31 PM5/31/12
to play-fr...@googlegroups.com
Do I have to create the form on the front end (view) using @helper package? Can I create the form using plain HTML?

biesior

unread,
May 31, 2012, 2:42:26 PM5/31/12
to play-fr...@googlegroups.com
Yes you can, helpers are useful when you are editing some record, creating blank form you can just use pure HTML

Zihao Yu

unread,
May 31, 2012, 2:47:59 PM5/31/12
to play-fr...@googlegroups.com
Thank you. I'm asking because I find helpers not working very well with Twitter Bootstrap. I've tried the custom field constructor for twitter bootstrap, but I still found it difficult to apply classes to form elements (such as class="span6"). Is there anyway to specify class attributes of form elements? I tried '_class="span6" but it didn't work.

Kevin Bosman

unread,
Jun 3, 2012, 9:44:14 AM6/3/12
to play-fr...@googlegroups.com
> I tried '_class="span6" but it didn't work.

You'll need to use 'class -> "span6"

biesior

unread,
Jun 4, 2012, 7:44:03 AM6/4/12
to play-fr...@googlegroups.com
As Kevin stated this works:

@inputText(userForm("firstName"),
'_label -> "Your name",
'class -> "required span10",
'minlength -> "3")

or you can do it with HTML (there's no Play's error/constraints messages  support in this sample, useful when sending forms with AJAX, other pre-validation suggested):

    <div class="row">
        <div class="span2">Company name <span class="required">*</span></div>
        <div class="span10">
            <input class="span10 required" minlength="3" type="text" name="name" id="name"
                   placeholder="Full name of your company"
                   value='@companyForm("name").value'/>
        </div>
    </div>

Zihao Yu

unread,
Jun 4, 2012, 9:32:46 AM6/4/12
to play-fr...@googlegroups.com
Thanks, that worked. Is there any client-side validation library that you can recommend?

biesior

unread,
Jun 4, 2012, 10:29:46 AM6/4/12
to play-fr...@googlegroups.com
Yes, second sample (html) has ie. class="required" and minlength="3", both of them are used by jQuery Validation plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Notice that although it's fast and easy to use, it's worth to validate also on server-side - remember that request can be manipulated or client-side JS validator may fail on some weird browser - in such case server-side validation should catch an errors as well and at least display minimal info instead of 'blind' saving incoming data.

sun

unread,
Jun 4, 2012, 11:33:01 AM6/4/12
to play-framework
The client is always a terorist.

biesior

unread,
Jun 4, 2012, 11:40:39 AM6/4/12
to play-fr...@googlegroups.com
Yay! why there's no "Like it" button on google groups? :D
Reply all
Reply to author
Forward
0 new messages