I have a button element in form builder as follows

$form['fieldset']['add_new_event_btn'] = array(
  '#value' => t('Add new event trigger'),
  '#type' => 'button',
  '#attributes' => array(
    'style' => 'margin-top:20px;width:200px;margin-right:275px;float:right',
  ),
  '#ajax' => array(
    // Function to call when event on form element triggered.
    'callback' => '::enable_event_trigger',
    // Effect when replacing content. Options: 'none' (default), 'slide', 'fade'.
    'effect' => 'fade',
    // Javascript event to trigger Ajax. Currently for: 'onchange'.
    'event' => 'click',
    'progress' => array(
      // Graphic shown to indicate ajax. Options: 'throbber' (default), 'bar'.
      'type' => 'throbber',
      // Message to show along progress graphic. Default: 'Please wait...'.
      'message' => 'loading',
    ),
  ),
);

But this button is act as the submit button , and there for the validation for other elements works and shows the error message on the next reload when i leave the page as it is, How can i rectify this problem ??

  • 1
    There is nothing like type as a button in drupal – vishal shah Aug 18 '16 at 11:19
  • What's the problem exactly? The button type exists to Format an action button. When the button is pressed, the form will be submitted to Drupal, where it is validated and rebuilt. The submit handler is not invoked. From what you've said it sounds like it's working perfectly – Clive Aug 18 '16 at 11:36
  • 1
    But i don't need to work it as submit button, want to work it as type='button' and do ajax requests .will that be possible ? – RubberDuckIsKing Aug 18 '16 at 11:45

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.