0

Possible Duplicate:
Custom validate and submit don't works

I am using Drupal 7 $form_state['values'] to get values from all fields, but the array is empty, and when I use dsm() there is no value.

screenshot

Hi, please this is maybe complex question but I really need help, I can't finish my task almost 3 days. If I need to write somewhere else you just say.

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 two don't work as expected
         $form['#validate'][] = 'mymodule_user_profile_form_validate';
         $form['#submit'][] = 'mymodule_user_profile_form_submit';

        //also try this one but nothing
        //$form['actions']['submit']['#submit'][] = 'mymodule_user_profile_form_submit'; 
    }
}

function mymodule_user_profile_form_submit($form, &$form_state) { 
//here I want to download image from other website and set as logo
}

function mymodule_user_profile_form_validate($form, &$form_state) { 
//here I need to check if checkbox is checked emty all other fields
    if ($form_state['values']['field_company_confidential'] == TRUE){
     //THEN set all other fields empty
        $form_state['values']['field_company_url']['und']['0'] = '';
    }

    return $form;
}
6
  • You should show the code you are using. There are many Drupal 7 modules that use $form_state['values']; $form_state['values'] is also used from modules included with Drupal. All those modules work as expected.
    – apaderno
    Jun 17, 2012 at 13:41
  • I want to make validation and to empty fields in validate function if one checkbox is checked. I am using form alter. I have another question on drupal.stackexchange.com/questions/34307/… I want to made some validation in want to get all values, and if checkbox is checked i want to empty all fields. Where do you want to put my code, because that is similiar question I wrote, but still no answer?
    – miske
    Jun 17, 2012 at 13:57
  • Just edit your question, and show the code you are using.
    – apaderno
    Jun 17, 2012 at 13:59
  • In other words, this is a follow-up to drupal.stackexchange.com/questions/34307/….
    – apaderno
    Jun 17, 2012 at 15:41
  • Yes It is. But as I said my validate and submit function don't work. At first time they have worked without problems, but later I added two fieldsets using Group field module. Next I added some code using #states and now I can't call these functions.
    – miske
    Jun 17, 2012 at 15:45

0

Browse other questions tagged or ask your own question.