We can setup some form elements like this:-
<input type="select" name="somename[1]"><option>test</option></select>
I know this question was answered but I think there's an easier way which is less verbose and you only need to change the number of fields (or pass it as an argument when getting the form).
function test_form() { $form['#tree'] = TRUE; // This is to prevent flattening the form value $no_of_fields = 5; // The number of fields you wish to have in the form // Start adding the fields to the form for ($i=1; $i<=$no_of_fields; $i++) { $form['selected'][$i] = array( '#type' => 'select', '#title' => t('test'.$i), '#required' => TRUE, '#options' => array( 'Action' => t('Action'), 1 => t('Move to Inactive Inventory'), 2 => t('Move to Wish/ Offer list'), 3 => t('Delete Item'), ), '#default_value' => 'Action', ); } // Add the submit button $form["submit"] = array( "#type" => "submit", "#value" => "Submit", ); }
No comments:
Post a Comment