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>
<!--?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
- 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
// ...
} - associate a type to the button
<button type="button" onclick="showFacebookPost(jQuery);">
<!--?php echo Text::_('JOFBK_VIEW_POST'); ?-->
</button>
<!--?php echo Text::_('JOFBK_VIEW_POST'); ?-->
</button>
