Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing multiple values with hidden input fields

Tags:

With a select tag, it is possible to post multiple values using only HTML by selecting more than one option?

For example:

<select multiple="" >     <option value="1"/>     <option value="2"/>     <option value="3"/> </select> 

Is it possible to pass more than one value as one would achieve with the previous example using one or more <input type="hidden"> fields? Again, strictly with HTML.

like image 618
David Avatar asked Jun 18 '10 20:06

David


People also ask

Are hidden inputs safe?

It's not safe to keep hidden input, because anyone can inspect your input element and find out the information you stored in that hidden input.

Can an input have multiple values?

Definition and Usage. The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input types: email, and file.


1 Answers

Use [ ] in the field name to send multiple values:

<input type="hidden" name="your_field_name[]" value="1" /> <input type="hidden" name="your_field_name[]" value="2" /> <input type="hidden" name="your_field_name[]" value="3" /> 

You will get an array of values in the your_field_name field.

like image 81
Victor Stanciu Avatar answered Nov 02 '22 06:11

Victor Stanciu