Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » submit Ajax

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 706 Views
  • Drumstick
    Avatar
    Community Member
    20 Posts

    submit Ajax Link to this post

    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!

  • Drumstick
    Avatar
    Community Member
    20 Posts

    Re: submit Ajax Link to this post

    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...

    706 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.