mercredi 27 juillet 2016

Submitted data doesn't get stored in database and i get redirected after submit

Hi i am working on php Laravel,and i am trying to submit data from a modal,and i want it to,simply close the modal after submission is successful,not redirect.But neither is working,so after submit i am being redirected,and after submit,there is no added data into the database.

So after filling the data in the form,press submit,it redirects me to the \ page,and i check the database,nothing is added.I can however extract data from it,so it's not the connection or the config.

I want to stay on the same page after submitting,with just closing the modal(i will disply a success later).

This is my in-modal form :

<div class="modal fade" id="myModal" role="dialog">
   <div class="modal-body">  

        <form id="eventForm" method="post" action="createEvent">
            //a couple inputs
            //a submit button
        </form>
   </div
</div>

This is the jQuery handling the data submission and non redirection

$(document).ready(function() {

$('#eventForm')
      .formValidation({
           framework: 'bootstrap',
          //icon,fields validation
       })            
      .on('success.form.bv', function (e) {
       e.preventDefault();
          var $form = $("#eventForm"),
          url = $form.attr('action');
           $.post(url, $form.serialize()).done(function () {
               $("#myModal").dialog("close");
            });
            });
            });

My route

 route::post('createEvent' , 'EventsController@store');

The controller handling the request

public function store(Request $request)
{
    $event= new event();

    //retrieving the data here

    $event->name = $request->name;
    $event->description = $request->description;
    $event->ending_date = $request->ending_date;
    $event->starting_date = $request->starting_date;
    $event->assigned_to = $request->assigned_to;
    $event->save();
}

The namespacing and uses are correct but i can post them if you want. Any suggestions ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire