Hi I have a extbase typo3 extension.It contain a model window with a form.On submit an ajax call updates the underlying table via updateAction.My problem is that how to get the form argument via getArgument() method in controller.My code is given below
My form is
<form id="updatewindow" method="POST" name="iframe">
<p><label for="fields">' + $(title).html() + ':</label>
<input type="text" value="' + cell_data + '" name="tx_suserform_userform[newUser][name]"></p>
</form>
Ajax Call
url_update = '<f:uri.action action="updateFileds" absolute="1" noCacheHash="1"/>';
jQuery.ajax({
url: url_update,
type: "POST",
data: params,
success: function (data) {
if (data == 'true') {
location.reload();
} else {
}
}
});
In my controller I wrote
$post_val = $this->request->getArgument('name');
but it returns error and
$this->request->getArguments()
only return controller name and action
You can get the form data using JavaScripts FormData
object:
url_update = '<f:uri.action action="updateFileds" absolute="1" noCacheHash="1"/>';
var params = new FormData(jQuery('#updatewindow').get(0));
jQuery.ajax({
url: url_update,
type: "POST",
data: params,
success: function (data) {
if (data == 'true') {
location.reload();
} else {
}
}
});
You should probably render your form using fluid, otherwise some stuff extbase relies on will be missing from the form (check the hidden div in any fluid generated form).
To get the URL to POST the data to, I'd recommend using the extension typoscript_rendering
- it's made for this exact purpose. It generates an URL which won't return the whole HTML page, but only the result from the template of the called action. You need to have cHashes enabled to use it.
$this->request->getArguments()
receives the post/get arguments in the format
$pluggin_signature['argument']
so I passed the parameters in that format from ajax.Here is my code
url_update = '<f:uri.action action="updateFileds" absolute="1" noCacheHash="1"/>';
var params = {'tx_pluggin_signature[name]':'test','tx_pluggin_signature[phone]':'(456) 456-2345'};
jQuery.ajax({
url: url_update,
type: "POST",
data: params,
success: function (data) {
if (data == 'true') {
location.reload();
} else {
}
}
});