Web application : passing data during http redirect

2,318 views
Skip to first unread message

bsr

unread,
Feb 11, 2012, 6:35:37 PM2/11/12
to golang-nuts
Hello,
I have seen many web applications does a server side validation of
data (during create form is submitted through POST), and then redirect
to the same form highlighting the error fields.

To make this possible, one has to pass the data from POST handler to
the redirect handler (GET/create form handler). I can think about
couple of ways passing data
- through request parameters
- cookie
- persistance
these all are not ideal if I need better control.
Say my form has 5 fields, and 3 fields has various validation error
and I want to highlight the error next to the corresponding field. It
would be ideal if I could pass a data structure during redirect. Is
this a possibility? How would you handle this.
thanks,
bsr.

Rodrigo Moraes

unread,
Feb 11, 2012, 8:00:06 PM2/11/12
to golang-nuts
On Feb 11, 9:35 pm, bsr wrote:
> Hello,
> I have seen many web applications does a server side validation of
> data (during create form is submitted through POST), and then redirect
> to the same form highlighting the error fields.

The common practice is to redirect only after successful forms. So
forms with errors are treated by the same POST request, and so have
access to the data.

> It
> would be ideal if I could pass a data structure during redirect. Is
> this a possibility? How would you handle this.

There's no way other than passing it in the query arguments or setting
a cookie.

-- rodrigo
Message has been deleted

bsr

unread,
Feb 11, 2012, 8:18:52 PM2/11/12
to golang-nuts
Rodrigo, Peter .. thank you very much for this info.
Rodrigo, I am just reading through your session package which support
flash messages. thanks for the effort.


On Feb 11, 8:02 pm, "peterth...@ymail.com" <peterth...@ymail.com>
wrote:
> Most applications respond to the POST with the highlighted form. They
> don't redirect.

nvcnvn

unread,
Feb 11, 2012, 8:49:37 PM2/11/12
to golang-nuts
Not sure if I understand correctly your case, and here is my case:
1. The form has a textbox1 that must be validation (reqquired),
textbox2 is optional.
2. Labe the empty textbox1, type some on textbox2, submit the form.
You get the error noitice next to the textbox1 and textbox2 fill with
your typed data.
If your case is the same I do not thing we need to pass data during
http redirect
###########
if sumited && hasError {
<input type="text" name="textbox1" /><label> you error</label>
<input type="text" name="textbox2" value=r.FormValue("textbox2") />
} else if submited {
<b>You are done!,/b>
} else {
<input type="text" name="textbox1" />
<input type="text" name="textbox2" />
}
########

bsr

unread,
Feb 12, 2012, 6:48:53 AM2/12/12
to golang-nuts
Sorry that I wasn't clear, but what you mentioned is client side
validation. But, if the validation requirement is bit complex or
doesn't want to mix up with ui code, then I may do the validation at
server side and pass the result.
But, the previous answers corrected a wrong assumption I had, and I
will try without redirecting.
If I indeed need to pass data during redirect, I may use req params or
cookies.

thanks again for all your help
Reply all
Reply to author
Forward
0 new messages