Skip to main content
added 74 characters in body
Source Link
niksmac
  • 7.7k
  • 3
  • 31
  • 69

Hello I have created a custom form added a # ajax callback on form submit

    $form['hotel_book_form']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Check Availability'),
    '#ajax' => array(
      'callback' => "list_rooms",
      'wrapper' => "replace_hotelbook_div",
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );

); and and I have added this wrapper as suffix to the form

    $form['hotel_book_form'] = array(
    '#type' => 'fieldset',
    '#title' => t('Book Hotel'),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => '<div id="replace_hotelbook_div"></div>',
  );

);

but when I click on form's submit button the page gets simply reloaded and the ajax callback function does not fire.

Hello I have created a custom form added a # ajax callback on form submit

$form['hotel_book_form']['submit'] = array(
'#type' => 'submit',
'#value' => t('Check Availability'),
'#ajax' => array(
  'callback' => "list_rooms",
  'wrapper' => "replace_hotelbook_div",
  'method' => 'replace',
  'effect' => 'fade',
),

); and I have added this wrapper as suffix to the form

$form['hotel_book_form'] = array(
'#type' => 'fieldset',
'#title' => t('Book Hotel'),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div id="replace_hotelbook_div"></div>',

);

but when I click on form's submit button the page gets simply reloaded and the ajax callback function does not fire.

Hello I have created a custom form added a # ajax callback on form submit

    $form['hotel_book_form']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Check Availability'),
    '#ajax' => array(
      'callback' => "list_rooms",
      'wrapper' => "replace_hotelbook_div",
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );

and I have added this wrapper as suffix to the form

    $form['hotel_book_form'] = array(
    '#type' => 'fieldset',
    '#title' => t('Book Hotel'),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => '<div id="replace_hotelbook_div"></div>',
  );

but when I click on form's submit button the page gets simply reloaded and the ajax callback function does not fire.

Source Link
Somya Gupta
  • 606
  • 7
  • 21

Drupal 7 #ajax callback on form submit

Hello I have created a custom form added a # ajax callback on form submit

$form['hotel_book_form']['submit'] = array(
'#type' => 'submit',
'#value' => t('Check Availability'),
'#ajax' => array(
  'callback' => "list_rooms",
  'wrapper' => "replace_hotelbook_div",
  'method' => 'replace',
  'effect' => 'fade',
),

); and I have added this wrapper as suffix to the form

$form['hotel_book_form'] = array(
'#type' => 'fieldset',
'#title' => t('Book Hotel'),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div id="replace_hotelbook_div"></div>',

);

but when I click on form's submit button the page gets simply reloaded and the ajax callback function does not fire.