how can I add a field to a form submission upon submit that will have the same value as the field name "mail" but with the name "email"
2 Answers
I think it'll work if you implement hook_form_submit() hook for this form, and in that function set the value of one field to another.
E.g.,
FORM_ID_form_submit($form, &$form_state) {
$form_state['values']['email'] = $form_state['values']['mail'];
}
If your fields are fields of a content then replace the above line with this:
$form_state['values']['email']['und'][0]['value'] = $form_state['values']['mail']['und'][0]['value'];
-
the form submit when i put in this code doesnt seem to be reach. It goes to the page that I have marked as the form action and never gets there.– DianaCommented Apr 25, 2017 at 20:30
-
-
My bad, didn't realize you were asking for Drupal8. Sorry can't help. Haven't looked into Drupal8 yet.– AmirCommented Apr 26, 2017 at 21:34
In Drupal 8 I did it this way, there may be a shorter way though
$value=$form_state->getValue('field_name');
$number=($value[0]['value']);
$form_state->setValue('other_field',$number);