Take for example the CKEditor admin page, where at file browser settings you can choose IMCE at file browser type. Then you click Save.

Can you program this? I mean in PHP; because I could also find out which SQL query is done, and use drush sql-query, but that is not what I mean. I want to program it because I have a multisite with about 70 sites.


Eric J.


Yes, use hook_form_FORM_ID_alter()

function MYMODULE_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
  $form['#validate'][] = 'MYMODULE_some_validate_function';
  $form['#submit'][] = 'MYMODULE_some_submit_function';

function MYMODULE_some_validate_function($form, &$form_state) {
  if ($form_state['values']['foo'] !== 'bar']) {
    form_set_error('foo', t('Foo must be bar'));

function MYMODULE_some_submit_function($form, &$form_state) {
  // Do something.

It's not possible to be any more specific than that as 'admin' pages vary in their structure. Most are created using a system_settings_form(), though, so there's a reasonable amount of consistency.

It's also worth noting that a form created with system_settings_form() saves its data in the variables table, so you can accomplish the same thing in a lot of cases with variable_set():

variable_set('site_name', 'New name');
  • Thanks. In my_form_alter I said $form_state["values"]["filebrowser"]="imce". But I do not know how to program what you do on the UI page: click the Save submit button. Think about all the post data, how do I do that? – ericj Jan 6 '14 at 19:29

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.