mysql - Laravel 4 Sending An Entire Form as a variable with jQuery Form Plugin -
how use jquery form plugin send ajax version of form working on variable can sent database? wanting pull several inputs (such order name , date) , put in database or organizational purposes want able store entire order form in base form can called , edited later if need be. jquery form plugin seems ideal doing sends form file destination, needing sent variable can send database. if has ideas on how appreciated! thank much!
if want send form laravel, need jquery do it:
jquery('#savebutton').click(function(evnt) { var href = $("#"+event.target.id).closest('form').attr('action'); var form = $("#"+event.target.id).closest('form').attr('id'); jquery.post(href, jquery("#"+form).serialize()) .done(function(data) { if (data.success == "true") { /// need in case of success } else { /// need in case of error } }) return false; });
what does:
1) set event click on button id savebutton
2) form action
3) form id
4) serialize whole form json
5) post form action url
6) controller supposed return data
, success
property, check , whatever need in front end
in laravel controller need to:
input::get('email'); input::get('password');
you can do:
post::create(input::all());
note input::all()
gives array of fields, can remove don't need. example explain there lots of ways store user fields in table, one, simple one:
$post = post::find(input::get('id')); $post->title = input::get('title'); $post->body = input::get('body'); $input = input::all(); unset($input['title']); unset($input['body']); $post->userfields = json_encode($input); $post->save();
as noted in comment, can make use input::except() , loops need.
if need use fields form::model()
, can stuff them model:
$post = post::find(1); foreach(json_decode($post->userfields) $key => $value) { $post->attributes[$key] = $value; }
and pass it:
form::model($post...);
Comments
Post a Comment