3

How can I pass a boolean value in a form to a controller without the user being able to see or edit it? I'm assuming hidden_field is used for this, but how can I then assign a value to the variable?

Thanks for the help -Pat

1
  • 2
    Don't trust that a value won't be modified by the user just because it's hidden in a form. Commented Sep 15, 2009 at 21:47

1 Answer 1

4

Pat,

I am slightly confused by what you mean with the 'but how can I then assign a value to the variable', but I'll give this a go.

First off, you are correct in the hidden_field bit.

<%= hidden_field_tag 'some_name', true %>

or, alternatively

<%= hidden_field_tag 'some_name', false %>

You get the point with that, I'm sure.

From there, in your controller, when the form is submitted you would get the value of that field like so:

some_boolean = params[:some_name]

Obviously variable names would be different, but that's the general gist of it all.

Good luck!

Sign up to request clarification or add additional context in comments.

1 Comment

sorry I wasn't very clear, I had a mysql field that was susposed to take a boolean value and depending on the form I wanted to assign it true or false. I ended up using a radio button that wasn't rendered on the page that had the correct value to pass into mysql. Thanks for the help though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.