I want to add one or two fields in user register form, for that i have made alter hook to inject field by the below code:

function kaz_module_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id) 
{  
  $form['account']['bike_reg_file'] = array(
    '#type' => 'file',
    '#title' => t('Enter bike registration file'),
    '#default_value' => '',
    '#description' => t('Help text goes here'),
  );

  $form['account']['sex'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter sex'),
    '#default_value' => '',
    '#description' => t('Type male or female'),
  );

  $form['actions']['submit']['#submit'][] = 'kaz_module_user_form_submit_handler';

  return $form;
}

.....................
But after that in submit function i am not able to get those fields value, see my code below:

function kaz_module_user_form_submit_handler(array &$form, FormStateInterface $form_state)
{
  $bike_reg_file = $form_state->getValue('bike_reg_file');
  $sex = $form_state->getValue('sex');
  echo '<pre>';
  var_dump($bike_reg_file);
  var_dump($sex);
  echo '</pre>';
  die();
}

How can i get that value and then how can i save the value for that registered user's?
Do i need to plan in another way to achieve this goal?
Also here sex field is giving value which was text field, but bike_reg_file is giving me blank string, where it was a file field.
Thanks

Comments

ashique12009 created an issue. See original summary.

ashique12009’s picture

Issue summary: View changes
ashique12009’s picture

Issue summary: View changes
ashique12009’s picture

Issue summary: View changes
rambabburi’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.