Reputation: 1099
I want to create a CakePHP form with no action. I want to handle all with JavaScript. How can I create a CakePHP form without an action?
In HTML I would do:
<form action="#">
Upvotes: 1
Views: 1480
Reputation: 1345
Can't you prevent the action with e.preventDefault or return false in your javascript/jquery?
jquery:
$('#yoursubmitbutton').submit(function(e){ e.preventDefault;});
Would do the trick i guess..
Upvotes: 0
Reputation: 1099
I solved the problem by just add default = false
to the form create parameters.
Upvotes: 2
Reputation: 19
EDIT: Sorry did not read that careful, preventDefault should do the trick :)
If you want to handle it with JavaScript or jQuery you can simply skip to add the html form tags. Just stick with a unique ID for every input of the form and use a JS or jQuery selector to grab the value from it. example:
<input type="text" id="textfield">
<input type="submit" id="submit">
<script type="text/javascript">
$('#submit').click(function() {
var textfieldInput = $('#textfield').val();
var postData = {
'textfieldInput' : textfieldInput
}
$.ajax({
type: "POST",
url: "yourBackend.php",
data: postData
}).done(function( data ) {
alert(data);
});
});
</script>
Upvotes: 0