Can I force a form to submit empty fields?

I’ve seen some Java implementations but is there a simpler way to force
a form to submit ALL fields even if some are empty? I need a consistent
number of responses to tabulate the results, so having NULL or empty
strings doesn’t bother me. The programmatic challenges of trying to
reconstruct survey results outweigh the benefits of reducing a few
database NULLs. Thanks in advance!

In Rails if the form field is empty it will submit an empty params
value… Thats how it works by default.

Maybe an example would be better?

If you had two inputs, i1 and i2 and i1 had the word here and i2 was
empty when you press submit you get this back to you controller:

i1=“here” i2=“”

and if there is no validation rules in the model that would be saved
with the blank field…

Sounds like you are thinking Java and not Rails…

On Jan 30, 2:49 pm, Taylor S. [email protected]

Freddy A. wrote:

In Rails if the form field is empty it will submit an empty params
value… Thats how it works by default.

Maybe an example would be better?

If you had two inputs, i1 and i2 and i1 had the word here and i2 was
empty when you press submit you get this back to you controller:

i1=“here” i2=“”

and if there is no validation rules in the model that would be saved
with the blank field…

Sounds like you are thinking Java and not Rails…

On Jan 30, 2:49�pm, Taylor S. [email protected]

Thanks for the response. My form is not tied to a model and is
generated dynamically. But I have my submission button redirect to a
view that displays the params - many fields that are skipped are NOT
submitted as params. I see now that is DOES submit empty text fields.
But it does not submit empty radio button groups or checkboxes. I need
tall form elements as params even if they aren’t checked / selected /
filled out. Since the forms are generated dynamically I cannot manually
add empty fields on save. So I guess my refined question is:

How do I force the submission of radio buttons / checkboxes if empty?

I solved this issue with hidden fields. You must put a hidden field
with the SAME NAME with the value = ‘0’ (or whatever you want to mean
unchecked). This sets a default of ‘0’ which is overwritten by the
checkbox.
However, the hidden field MUST be after the checkbox for it to work,
which is counter-intuitive. If the hidden field is before it will
overwrite the real value, making all values ‘0.’

It was funny because I was thinking checkbox is different when I wrote
my reply but left it out anyways…

You have to specify what the default is and that should get you 1 or 0
or yes or no…

check_box(“product”, “published”, {}, ‘1’, ‘0’)
or
check_box(“puppy”, “gooddog”, {}, “yes”, “no”)

Btw the check_box form helper will great a hidden field anyway…