Drupal Form Validation: Illegal selection detected

I have a problem validating a Drupal 6 form.

I have two dropdowns. The parameters of the second drop-down menu (Project) depend on the selected option of the first drop-down list (Client). When a client changes, I get all projects from this client.

Now that the form is verified, another client is selected as the default, the parameters for the projects are not the same as when building the form. This means that the selected project option is not in the parameters array that was created for the form.

Is it possible to change an array of parameters to validate the form? What is the array of parameters for the project in the validation built depending on the choice of the client?

+3
source share
2 answers

, , , , . , $options , ( ).

, $form_state['values'], :

function your_form(&$form_state) {
  // ... other form building stuff
  // Start with initial default options for project select
  $project_options = array('- Please select client first -');
  // Adjust, if client already selected
  if (isset($form_state['values']) && $form_state['values']['your_client_select']) {
    $selected_client = $form_state['values']['your_client_select'];
    $project_options = your_function_to_build_project_options_by_client($selected_client);
  }
  // ... build project select using those options
  // ... other form building stuff
}
+2

- . . . .

0

All Articles