#992928 by das-peter, David_Rothstein: Fixed Command line (Drush) install fails on SQLite (#limit_validation_errors doesn't work for programmatic form submissions)

merge-requests/26/head
Angie Byron 2010-12-21 21:05:22 +00:00
parent 3999984bf8
commit bf534a219f
3 changed files with 49 additions and 1 deletions

View File

@ -661,9 +661,14 @@ function drupal_form_submit($form_id, &$form_state) {
// Merge in default values.
$form_state += form_state_defaults();
$form = drupal_retrieve_form($form_id, $form_state);
// Populate $form_state['input'] with the submitted values before retrieving
// the form, to be consistent with what drupal_build_form() does for
// non-programmatic submissions (form builder functions may expect it to be
// there).
$form_state['input'] = $form_state['values'];
$form_state['programmed'] = TRUE;
$form = drupal_retrieve_form($form_id, $form_state);
// Programmed forms are always submitted.
$form_state['submitted'] = TRUE;

View File

@ -1222,6 +1222,15 @@ class FormsProgrammaticTestCase extends DrupalWebTestCase {
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => 2)), TRUE);
$this->submitForm(array('textfield' => 'dummy value', 'checkboxes' => array(1 => NULL, 2 => NULL)), TRUE);
// Test that a programmatic form submission can correctly click a button
// that limits validation errors based on user input. Since we do not
// submit any values for "textfield" here and the textfield is required, we
// only expect form validation to pass when validation is limited to a
// different field.
$this->submitForm(array('op' => 'Submit with limited validation', 'field_to_validate' => 'all'), FALSE);
$this->submitForm(array('op' => 'Submit with limited validation', 'field_to_validate' => 'textfield'), FALSE);
$this->submitForm(array('op' => 'Submit with limited validation', 'field_to_validate' => 'field_to_validate'), TRUE);
// Restore the current batch status.
$batch = $current_batch;
}

View File

@ -1377,6 +1377,7 @@ function form_test_programmatic_form($form, &$form_state) {
'#title' => 'Textfield',
'#type' => 'textfield',
);
$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#options' => array(
@ -1388,6 +1389,39 @@ function form_test_programmatic_form($form, &$form_state) {
'#default_value' => array(1, 2),
);
$form['field_to_validate'] = array(
'#type' => 'radios',
'#title' => 'Field to validate (in the case of limited validation)',
'#description' => 'If the form is submitted by clicking the "Submit with limited validation" button, then validation can be limited based on the value of this radio button.',
'#options' => array(
'all' => 'Validate all fields',
'textfield' => 'Validate the "Textfield" field',
'field_to_validate' => 'Validate the "Field to validate" field',
),
'#default_value' => 'all',
);
// The main submit button for the form.
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
// A secondary submit button that allows validation to be limited based on
// the value of the above radio selector.
$form['submit_limit_validation'] = array(
'#type' => 'submit',
'#value' => 'Submit with limited validation',
// Use the same submit handler for this button as for the form itself.
// (This must be set explicitly or otherwise the form API will ignore the
// #limit_validation_errors property.)
'#submit' => array('form_test_programmatic_form_submit'),
);
if (!empty($form_state['input']['field_to_validate']) && $form_state['input']['field_to_validate'] != 'all') {
$form['submit_limit_validation']['#limit_validation_errors'] = array(
array($form_state['input']['field_to_validate']),
);
}
return $form;
}