Be careful to check the type of buttons in a Joomla form (or a HTML form)!!!

Example

I want to associate a particular action with a button on a form.

I have defined for this a function called when clicking

<button onclick="showFacebookPost(jQuery);">
    <!--?php echo Text::_('JOFBK_VIEW_POST'); ?-->
</button>

The concern is that the default submission method ("submit") of the form is called

Method to fix the problem

  1. prevent click-related event from calling the default behavior
    <button onclick="showFacebookPost(jQuery, event);">
        <!--?php echo Text::_('JOFBK_VIEW_POST'); ?-->
    </button>

    function showFacebookPost($, event) {
      // empecher le comportement par défaut
      event.preventDefault();
      console.log('Événement reçu :', event);
      // traitement proprement dit
      // ...
    }
  2. associate a type to the button
  3. <button type="button" onclick="showFacebookPost(jQuery);">
        <!--?php echo Text::_('JOFBK_VIEW_POST'); ?-->
    </button>