I’m probably being stupid, because its Friday afternoon, but I just can’t work this out.
What I want is to have a form where users can add infinite “records”. To do this they click an “add record” button. This runs javascript which adds a new row (tr) to a table within the <form>.
This new row has three input fields.
What I want is for this to be sent to the post variable in a format such as (but not exact if it can’t be done, but there’s a better way):
$_POST['record'] = array(
array(
"input1" => "value",
"input2" => "value",
"input3" => "value"
),
array(
"input1" => "value",
"input2" => "value",
"input3" => "value"
),
array(
"input1" => "value",
"input2" => "value",
"input3" => "value"
),
);
I know you can get arrays by using the name like so:
<input type="text" name="record[]" />
But this is only 1 input element. Is there any way to get a structure like above with 3 elements?
Thank you.
You can’t easily get what you’re looking for exactly, but you can use
name="record[input1][]"(andinput2etc.) and the result is:You could then transform it into your desired format like so: