2

I am using Drupal 7 and creating a form with some fields like position.

function mycustom_form($form, &$form_state){
  $form = array();
  $form['position'] = array(
   '#type' => 'textfield',
   '#title' => t('Position for the magnifier'),
   '#options' => array('left' => 'Left', 'right' => 'Right','up'=>'Up','down'=>'Down'),
   '#required' => TRUE,
  );
  return system_settings_form($form);
}

When I click on save with any position selected, these values are saved. So I am not getting where these values are saved and how to use these values in a JavaScript file... I am saving these values in a database.

5

If you use system_settings_form function your data will be saved in 'variable' table. To get saved data you may use variable_get function.

To show saved value in form

       function mycustom_form($form, &$form_state){
         $form = array();
         $form['position'] = array(
           '#type' => 'textfield',
           '#title' => t('Position for the magnifier'),
           '#options' => array('left' => 'Left', 'right' => 'Right','up'=>'Up','down'=>'Down'),
           '#default_value' => variable_get('position', ''),
           '#required' => TRUE,
         );

         return system_settings_form($form);
       }

If you want to use saved data from your form in the javascript, you may use next code

drupal_add_js(array('myModule' => array('position' => variable_get('position', ''))), 'setting');

Then this data will be available in javascript in Drupal.settings.myModule.position variable

  • I also need to use this position value (right/left etc) in javascript file. – jsh Aug 12 '15 at 7:31

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.