Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

submit Ajax


Reply

2 Posts   754 Views

Avatar
Drumstick

2 August 2013 at 6:28am Community Member, 20 Posts

Hi

I don't find the right solution for an Ajax submit through a form. I want to save the data in the database.

This is the jquery and this works...but the save works not

jQuery.noConflict();

(function($) {
$(document).ready(function() {
$("#ProductForm_ProductForm").submit(function() {

var Productcategory = $("#ProductForm_ProductForm_Productcategory").val();
var Productsubcategory = $("#ProductForm_ProductForm_Productsubcategory").val();
var Product = $("#ProductForm_ProductForm_Product").val();
var Price = $("#ProductForm_ProductForm_Price").val();
var Einheit = $("#ProductForm_ProductForm_Einheit").val();
var Description = $("#ProductForm_ProductForm_Description").val();

var Anzeige_von = $("#ProductForm_ProductForm_Anzeige_von").val();
var Anzeige_bis = $("#ProductForm_ProductForm_Anzeige_bis").val();
       var SecurityID = $("#ProductForm_ProductForm_SecurityID").val();
   var dataString = 'Productcategory='+ Productcategory + '&Productsubcategory='+ Productsubcategory + '&Product='+ Product + '&Price='+ Price + '&Einheit='+ Einheit + '&Description='+ Description + '&Anzeige_von='+ Anzeige_von + '&Anzeige_bis='+ Anzeige_bis + '&SecurityID='+ SecurityID;
//alert (dataString);return false;

$.ajax({
type: "POST",
url: "",
data: dataString,
success: function() {

alert(dataString);
}
});

return false;
});
});
})(jQuery);

this works not:

public function saveproduct(array $data, Form $form) {

parse_str(urldecode($this->requestParams['Product']),$data['Product']);

$p = $data['Product'];

// Debug::show($data);

$memberID = Member::currentUserID();

Session::set('product',$data['Product']);

   
$customerproduct = new Customerproduct();

$customerproduct->write();
$form->saveInto($customerproduct);

$customerproduct->CustomerID = $memberID;
$customerproduct->Product = $p;

$customerproduct->write();

Director::redirectBack();
return $form->sessionMessage('Ihr Produkt wurde gespeichert.', 'good');

}

Has somenon a tipp? I tried the other tipps here in the forum but it does not work. When I yous serialize then I have the code of the whole website.

Tanks for help!

Avatar
Drumstick

3 August 2013 at 12:54am Community Member, 20 Posts

ok, I have understand it...

in the jquery form I have to write the whole path of my url with the function at the end

somthing like

$.ajax({
type: "POST",
url: "http://localhost/mydomain/index.php/client/login/offer/ProductForm/AjaxSubmit",
data: dataString,
success: function() {

alert(dataString);
}
});

and then in the function I can get the data via a normal $_POST in my case for example $_POST['Product']

hope this helps someone else too...