I am working on a login form (information sent via https to a remote system), that by default contains a username field, a password field and a static hidden field (necessary in order to validate with the remote system).
There is one additional hidden field necessary, which should be built from the value of the username and the value of the existing hidden validation field, separated by an underscore, like this: username_hidden_id
Is it possible to achieve that after the form has been submitted? I tried to add the field using the form submit function, but that doesn't seem to work.
I could add this the mentioned field and generate it's value via JavaScript/jQuery, but I wouldn't like to have this field visible/public.
I have the following code:
function custom_login_form($form, $form_state) {
$form['username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#maxlength' => USERNAME_MAX_LENGTH,
'#size' => 15,
'#required' => TRUE,
);
$form['password'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#size' => 15,
'#required' => TRUE,
);
// Hidden validation field
$form['hidden_id'] = array(
'#type' => 'hidden',
'#value' => '1234',
);
// Submit button
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Log in'),
);
return $form;
}
function custom_login_form_validate(&$form, &$form_state) {
if (empty($form_state['values']['username'])) {
form_set_error('username', 'Please enter a username.');
$form_state['rebuild'] = TRUE;
}
if (empty($form_state['values']['password'])) {
form_set_error('password', 'Please enter a password.');
$form_state['rebuild'] = TRUE;
}
}
function custom_login_form_submit(&$form, &$form_state) {
if (isset($form_state['input']) && !empty($form_state['input']['username']) && !empty($form_state['input']['hidden_id'])) {
$form['username_hidden_id'] = array(
'#type' => 'hidden',
'#value' => $form_state['values']['username'] . '-' . $form_state['values']['hidden_id'],
);
}
}