Reputation: 681
I got these buttons inside a form which I want to NOT trigger a submit, they are simple html buttons
<?php echo $this->Form->create('Point'); ?>
...
<button class="btn">text</button> => this one shouldn't trigger a submit
...
<?php echo $this->Form->end(array('label' => 'add', 'div' => false, 'escape' => false, 'class' => 'btn btn-default btn-block')); ?>
however cakephp always handles these as submits, just as the regular form end buttons. Any way to prevent this?
I tried using jquery
$('.btn').click(function(e){
e.preventDefault();
return false;
});
But that won't work either.
Upvotes: 1
Views: 4512
Reputation: 56
Check It...
$('.btn').live('click', function(e){
e.preventDefault();
return false;
});
OR
$('.btn').on('click', function(e){
e.preventDefault();
return false;
});
Upvotes: 0
Reputation: 1299
Use
<button type="button" class="btn">text</button>
instead.
The default type
for button is submit
.
Upvotes: 2
Reputation: 4522
You could just create simple button instead of a submit button. If you put arguments inside $this->Form-end()
you'll get a submit button by default. But you could easily add extra buttons (with no function attached by default) and end the Form without a submit button.
Something like this should do
echo $this->Form->button('A button',
array('class' => 'btn'));
echo $this->Form->end();
Also, check other type of action-trigger buttons, like postButton and postLink, meybe those fit better for what you want to do instead of preventing default functions of buttons.
Upvotes: 1