Let’s say you’re making a blog application, and you’re trying to decide how to build the comment form for a particular post. Would you
- put the
blog_post_idas a hidden form field in the comment form, or would you - set the form action to
post_comment?blog_post_id=<id>and then grab it from theGETvariable instead?
Why?
My 2 cents:
If you put it into POST, then all your variables are in a consistent location when you’re trying to process the form. However, I find that often the blog_post_id will be in the URL anyway, so you’re sending a tiny bit of extra unneeded data (and have to go through the work of printing the hidden field).
Technically there really isn’t a whole lot of difference between the two options. Personally, I’d go with the hidden
POSTbecause the URL looks cleaner and you won’t have to worry about URL escaping the value*.*That should be a non-issue for a numeric id, but oh well…Re Edit:
This is totally up to you. If you want it there, you can put it there, but you don’t need to.
Again, there really isn’t a whole lot of difference…
vs.
The hidden input provides a better separation of concerns (on a micro-scale) and is IMHO slightly more readable, while the
GETvariable is one line less code… Take your pick. 🙂