FORM API adds word "edit" before the id of any form element. When I have to use the element in JS I have to add "edit" before element id.

Example if I have element $form['curdate'] then in drupal_add_js('#edit-curdate');

Why so

1 Answer 1


Drupal adds edit to denote that the element is an input element. It helps to identify form elements through CSS, and reduces the possibility of ID clashes with other elements on the page.

In case you're interested, this is done in the form_builder() function...and there's no easy way to override it system-wide.

You can easily override it for individual form elements though if it's bothering you:

$form['element'] = array(
  '#type' => 'textfield',
  '#title' => 'Some title',
  // ...
  '#id' => drupal_html_id('my-new-id')
  • Thanks....I am trying to use Jquery_ui datepicker but its not working in Drupal 7. so I thought the error might be due to JS using datapicker
    – Dharmender
    May 7, 2012 at 10:23
  • The UI datepicker works great for me in Drupal 7, are you trying to include it in a custom form? If so what's your code?
    – Clive
    May 7, 2012 at 10:26
  • Yes I am trying to use it custom form module. jquery_ui_add(array('ui.datepicker')); drupal_add_js('$(document).ready(function(){$("input#edit-curdate").datepicker({dateFormat: "yy-mm-dd"});});','inline'); drupal_add_css(drupal_get_path('module', 'jquery_ui') . "/ui.datepicker.css", 'module'); $form['curdate']=array( '#type'=>'textfield','#title'=>'Date*);
    – Dharmender
    May 7, 2012 at 10:33
  • Try: $form['element'] = array('#type' => 'date_popup', '#title' => 'Date', '#date_format' => 'd/m/Y');. That works perfectly for me. The date module has that date_popup widget built in so you don't need to add any CSS/JS yourself, Drupal will do it all for you
    – Clive
    May 7, 2012 at 10:34
  • I have installed Date module with all features.but following errors are displaying... Notice: Undefined index: #id in theme_date_popup() (line 663 of D:\wamp\www\drupal\sites\all\modules\date\date_popup\date_popup.module). Warning: Missing argument 1 for myform_data_entry_form() in myform_data_entry_form() (line 28 of D:\wamp\www\drupal\sites\all\modules\myform\myform.module). Warning: Missing argument 2 for myform_data_entry_form() in myform_data_entry_form() (line 28 of D:\wamp\www\drupal\sites\all\modules\myform\myform.module).
    – Dharmender
    May 7, 2012 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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