I want to send the form through ajax. I read some tutorials but i don't found a solution.
I create this CRUD with " php artisan make:auth "
Controller
protected function create(Request $request){
$users = new User;
$users->nume = $request['nume'];
$users->prenume = $request['prenume'];
$users->cnp = $request['cnp'];
$users->mobil = $request['mobil'];
$users->email = $request['email'];
$users->password = bcrypt($request['password']);
$users->save();
return Response::json();
}
Route
Route::post('/register',array(
'as' => 'create',
'uses' => 'Auth\AuthController@create'
));
Jquery
jQuery( document ).ready( function( $ ) {
$( '#continua1' ).on( 'submit', function() {
//.....
//show some spinner etc to indicate operation in progress
//.....
$.post(
$( this ).prop( 'action' ),
{
"_token": $( this ).find( 'input[name=_token]' ).val(),
"$users->nume": $( '#nume' ).val(),
"$users->prenume": $( '#prenume' ).val(),
"$users->cnp": $( '#cnp' ).val(),
"$users->mobil": $( '#mobil' ).val(),
"$users->email": $( '#email' ).val(),
"$users->password": $( '#password' ).val(),
},
function( data ) {
//do something with data/response returned by server
},
'json'
);
//.....
//do anything else you might want to do
//.....
//prevent the form from actually submitting in browser
return false;
});
});
FORM
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('nume') ? ' has-error' : '' }}">
<label for="nume" class="col-md-4 control-label">Nume</label>
<div class="col-md-6">
<input required="required" id="nume" type="text" class="form-control" name="nume" value="{{ old('nume') }}">
@if ($errors->has('nume'))
<span class="help-block">
<strong>{{ $errors->first('nume') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('prenume') ? ' has-error' : '' }}">
<label for="prenume" class="col-md-4 control-label">Prenume</label>
<div class="col-md-6">
<input id="prenume" type="text" class="form-control" name="prenume" value="{{ old('prenume') }}">
@if ($errors->has('prenume'))
<span class="help-block">
<strong>{{ $errors->first('prenume') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('cnp') ? ' has-error' : '' }}">
<label for="cnp" class="col-md-4 control-label">CNP</label>
<div class="col-md-6">
<input id="cnp" type="text" class="form-control" name="cnp" value="{{ old('cnp') }}">
@if ($errors->has('cnp'))
<span class="help-block">
<strong>{{ $errors->first('cnp') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('mobil') ? ' has-error' : '' }}">
<label for="mobil" class="col-md-4 control-label">Mobil</label>
<div class="col-md-6">
<input id="mobil" type="text" class="form-control" name="mobil" value="{{ old('mobil') }}">
@if ($errors->has('mobil'))
<span class="help-block">
<strong>{{ $errors->first('mobil') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation">
@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="button" id="continua1" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i> Continua
</button>
</div>
</div>
</form>