I'm using Drupal 7 and the Entityform module to build a form for people to fill in on my website.
This form will be filled in by a parent and contains some data about his child. There will be 2 buttons:
- 1 for submitting the form data (default submit button/function)
- 1 for submitting the form data + opening a new form (of the same type) for a 2nd child (custom submit button/function).
Since this 2nd child will have a lot of data (address, last name,...) that's the same as the first child I'd like to already have those fields filled in in the 2nd form (by using field values from the first form). The same can be repeated for a 3rd child, a 4th child,...
This is my code so far:
function extra_inschrijving_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'generiek_inschrijvingsformulier__entityform_edit_form'){
$form['submit2'] = $form['actions']['submit'];
$form['submit2']['#value']='Inschrijven en ook een broer inschrijven';
$form['submit2']['#weight']=100;
$form['submit2']['#submit'][1]='extra_inschrijving_default_wp_submit';
}
}
This code added another submit-button and attached a submit handler (this works).
function extra_inschrijving_default_wp_submit($form, &$form_state){
$values = &$form_state['values'];
$prepopulates = array(
'edit[field_entity_reference][und]' =>
$values['field_entity_reference']['und'][0]['target_id'],
'edit[field_1][und][0][value]' => $values['field_1']['und'][0]['value'],
'edit[field_2][und][0][value]' => $values['field_2']['und'][0]['value'],
);
$form_state['redirect'] = array(
'node/11',
array(
'query' => $prepopulates,
),
);
}
Here I copy some field values from the form that will be submitted into the new form that has to be filled in. The parent should still be able to change the fields if he wants to. Both the normal fields and the entity reference field (select list) are copied/prepopulated successfully, but if the parent changes the entity reference field on the new form it still contains the old, prepopulated value when he submits it (although visibly something else is selected in the list).
_
instead of camel-case.