Creating a form having two file type element, i want to check that if user uploaded file any file, then user must upload both file, so is there any way to add a validate function in system_settings_form.

  • 2
    As a side note, you may want to read through this, drupal.org/node/635046. The last time I tried to use two files on a setting form, I ran into this bug,
    – mpdonadio
    Jun 28, 2014 at 22:38

1 Answer 1


The system_settings_form should be used to set simple variables for your module, see the approved answer and related comment here:

Is "system_settings_form" voodoo?

If you want to be sure both form fields are filled out during submission you don't need a validate function -- you can set both fields as being required when you create your form array:

$form['SOMETHING']['#required'] = TRUE;

where something is your form field key.

If you have complex logic and your form isn't simply setting a configuration variable you will call with variable_get or variable_set later -- then implement a custom form_validate and form_submit function for your form as your form is not simply a variable settings form.

See the Form API Handbook. Also of use is this drupal $form lifecycle or workflow illustration. Lastly form validation helpers and submit handlers are touched on briefly on this page of the handbook.


Just to complete my answer, hook_form_alter can change many aspects of a form used by drupal.


You can add a custom validator on the form you use to build return system_settings_form($form); for an example see the Commerce Admin include file here: http://cgit.drupalcode.org/commerce/tree/includes/commerce_ui.admin.inc

They set:

$form['#validate'][] = 'commerce_currency_settings_form_validate';

in their form builder function then they provide a validation function:

 * Form validate handler for the currency settings form.
function commerce_currency_settings_form_validate($form, &$form_state) {
  // Ensure the default currency is always enabled.
  $default = $form_state['values']['commerce_default_currency'];
  $form_state['values']['commerce_enabled_currencies'][$default] = $default;
  • Thanks for your answer,I can't make that element a required field because form also having other element but i can do it with form alter or i just check my condition in submit handler, i Just wanna know that there is no such term (validate) in system_settings_form
    – Akash Jain
    Jul 8, 2014 at 6:30
  • please see my second Edit which I hope answers your question.
    – tenken
    Jul 8, 2014 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.