Saving Data from Laravel Form in Bootstrap Modal -
i have bootstrap modal dialog use laravel form register user.
here's code:
<div id="addpenggunamodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="modallabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="modallabel">tambah pengguna baru</h3> </div> <div class="modal-body"> {{ form::open(array('url'=>'users/addpengguna','class'=>'form-horizontal', 'method'=> 'post')) }} <ul> @foreach($errors->all() $error) <li>{{ $error }}</li> @endforeach </ul> <div class="control-group"> <label for="firstname" class="control-label">first name:</label> <div class="controls"> {{ form::text('firstname', null, array('class'=>'span3', 'placeholder'=>'first name')) }} </div> </div> <!-- /field --> <div class="control-group"> <label for="lastname" class="control-label">last name: </label> <div class="controls"> {{ form::text('lastname', null, array('class'=>'span3', 'placeholder'=>'last name')) }} </div> </div> <!-- /field --> <div class="control-group"> <label for="email" class="control-label">email address: </label> <div class="controls"> {{ form::text('email', null, array('class'=>'span3', 'placeholder'=>'email address')) }} </div> </div> <!-- /field --> <div class="control-group"> <label for="password" class="control-label">password:</label> <div class="controls"> {{ form::password('password', array('class'=>'span3', 'placeholder'=>'password')) }} </div> </div> <!-- /field --> <div class="control-group"> <label for="confirm_password" class="control-label">confirm password:</label> <div class="controls"> {{ form::password('password_confirmation', array('class'=>'span3', 'placeholder'=>'confirm password')) }} </div> </div> <!-- /field --> <div class="control-group"> <label for="type_user" class="control-label">tipe pengguna:</label> <div class="controls"> {{ form::radio('level', '1'); }} supervisor {{ form::radio('level', '0'); }} sales </div> </div> <!-- /field --> </form> </div> <div class="modal-footer"> {{ form::submit('simpan', array('class'=>'button btn btn-primary','id'=>'mdl_save_change'))}} <button class="btn" data-dismiss="modal" aria-hidden="true">batal</button> </div> {{ form::close() }} </div>
then use controller save details:
public function postaddpengguna(){ /* function add user in data pengguna */ $validator = validator::make(input::all(), user::$rules); if($validator -> passes()){ $user = new user; $user->firstname = input::get('firstname'); $user->lastname = input::get('lastname'); $user->email = input::get('email'); $user->password = hash::make(input::get('password')); $user->level = input::get('level'); /* save following details */ $user->save(); return redirect::to('pengguna'); } else { return redirect::to('index'); } }
but form doesn't save data database. have page called registration , works.
my questions:
- how trace post laravel form submit, there browser extension?
- how trace error log in laravel
- any ideas what's going on in problem?
thank in advance.
update
here's screenshot describe how works.
bootstrap modal:
when press submit button (blue button in modal) want save data db. function php shown above.
ps. don't use ajax call value form. when use ajax, error because token missing.
first of check action
, _token
field of form . add token field in form should include following line in form:
<input type="hidden" name="_token" value="{{csrf_token()}}">
to re-use bootstrap modal in project can check github link
Comments
Post a Comment