I made my custom module, and wanted to do some staff in the validation and submission handlers. My Fields are in two field sets:
- Member profile, with username and password
- Company profile, with company name, URL, location, and logo
I am also using the #states attribute on some fields, but everything works except the validation and submission handlers.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'user_profile_form':
// Only pre-render works.
$form['#pre_render'][] = 'mymodule_user_profile_form_pre_render';
// I try to empty fields with states attribute, but without success. Disabled work OK.
$form['field_company_url']['und']['0']['value']['#states'] = array(
'empty' => array(':input[name="field_company_confidential[und]"]' => array('checked' => TRUE)),
'disabled' => array(':input[name="field_company_confidential[und]"]' => array('checked' => TRUE)),);
// These don't work as expected.
$form['#validate'][] = 'mymodule_user_profile_form_validate';
$form['#submit'][] = 'mymodule_user_profile_form_submit';
// I also tried this one.
// $form['actions']['submit']['#submit'][] = 'mymodule_user_profile_form_submit';
}
}
function mymodule_user_profile_form_submit($form, &$form_state) {
// I want to download the image from another website and set as logo.
}
function mymodule_user_profile_form_validate($form, &$form_state) {
//I need to check if checkbox is checked to empty all other fields.
if ($form_state['values']['field_company_confidential'] == TRUE) {
$form_state['values']['field_company_url']['und']['0'] = '';
}
return $form;
}
When I try to access $form_state['values']
, I don't get any value.
What I am doing wrong?
return $form;
line needs to be removed.