FrediWeber
FrediWeber

Reputation: 1099

CakePHP create form with no action

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

Answers (3)

Warre Buysse
Warre Buysse

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

FrediWeber
FrediWeber

Reputation: 1099

I solved the problem by just add default = false to the form create parameters.

Upvotes: 2

Bj&#246;rn Ringmann
Bj&#246;rn Ringmann

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

Related Questions