Skip to main content
Known Participant
March 20, 2011
Question

Checking for form posting

  • March 20, 2011
  • 1 reply
  • 451 views

Hello again,

what is the best way to check if a form was submitted?

I use to put a hidden field within the form with value="1", then a cfparam with default="". If form value neq "" then [process form].

Do you have any better advice?

Thank you very much

This topic has been closed for replies.

1 reply

Inspiring
March 20, 2011

Well: you could test that the request method was a POST (if your form submission is a post, that is), via CGI.REQUEST_METHOD.  But what you really need to check is that the form fields you're expecting/needing are there... structKeyExists(form, "formFieldNameHere").  You should really check each form-scoped variable your "action page" needs before charging off and using it.  Check for existence, as well as it being "valid" according to whatever validation rules you have, eg: an "age" field needs to be a positive integer, or something like that.

What you should not do is to check one form field and then assume everything else is all-present and correct.

--

Adam

SilvestroAuthor
Known Participant
March 20, 2011

Thanks Adam,

and how can I do this, is cfparam enough? I know it has some constraints...

Inspiring
March 20, 2011

Not only is cfparam not enough, it will sabotage what you say you are trying to accomplish.  Read Adam's answer again, and take it literally.