Hacker News new | past | comments | ask | show | jobs | submit login

It's nice to make an id called "school[school_id][4]" to match the name attribute of the input field.

(In case you don't recognize it php will automatically turns names that look like that into an array.)

Or if you are trying to name fields from a multi dimensional array. Say name['foo']['bar'] - you would name the id name_foo_bar

Simple enough, except when you also have an array: name['foo_bar'] - which looks identical to the first one.

Now that you can use other characters besides _ to separate the fields that helps a ton.




>>(In case you don't recognize it php will automatically turns names that look like that into an array.)

PHP does not have access to IDs of HTML elements. Or did you mean something else?


He meant the name attributes on form elements.

When a form containing <input type="text" name="foo" value="bar"> is submitted, $_POST['foo'] === 'bar' in PHP. (And it works similarly for other server-side programming languages.)


That's true, but not at all what he means. He means:

  <input type="text" name="foo[bar][]" value="yaw" />
will result in:

  $_POST['foo'][0] === "yaw";
In other words you can have a form create multidimensional arrays.


I was merely replying to the “PHP does not have access to IDs of HTML elements” statement, but good job on the additional explanation.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: