I have got my modal, here code
<!-- Modal -->
<div class="modal fade" id="box-modal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><!-- Aqui va el titulo de la pagina modal -->@yield('modal_title')</h4>
</div>
<div class="modal-body">
@yield('modal_body')
<div class="alert hidden" id="modal-alert"></div>
<!--Aqui va el cuerpo de la página modal -->
</div>
<div class="modal-footer">
<!-- Aquí va el pie de la pagina modal -->
@yield('modal_footer')
</div>
</div>
</div>
</div>
<!-- Fin de Modal -->
I call to my modal with a link
<a id="link-modal" class='btn btn-primary pull-right' data-toggle='modal' data-target="#box-modal"><i class='fa fa-plus'></i> Alta usuario</a>
Inside of my modal in modal_body I show a form:
@section('modal_body')
{{ Form::open(array('id' =>'formuser-create', 'role' => 'form', 'class' => 'form-horizontal')) }}
<div class="form-group">
{{ Form::label('inputuser', 'Nombre de usuario', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::text('inputuser','', array('placeholder' => 'Introduce la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputpassword', 'Contraseña', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::password('inputpassword','', array('placeholder' => 'Introduce la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputpassword1', 'Confirmar constraseña', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::password('inputpassword1','', array('placeholder' => 'Vuelve a introducir la contraseña...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('inputemail', 'Email', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::text('inputemail','', array('placeholder' => 'Introduce el email...', 'class' => 'form-control input-md')) }}
</div>
</div>
<div class="form-group">
{{ Form::label('es_admin', '¿Es administrador?', array('class' => 'col-md-4 control-label')) }}
<div class="col-md-5">
{{ Form::checkbox('es_admin',1,false) }}
</div>
</div>
{{ Form::close() }}
@stop
@section('modal_footer')
<div class='form-group text-center' id='editor-actions'>
{{ Form::submit('Guardar', ['class' => 'btn btn-success']) }}
{{ Form::reset('Limpiar', ['class' => 'btn btn-primary']) }}
</div>
@stop
When I press the button submit, I want to call to the method 'Create' of the Controller, for add an user. I make it with jquery ajax
$("formuser-create#submit").on("submit",function(e)
{
e.preventDefault();
var request = $.ajax({
type:'POST',
url:'users/Create',
data:$("#formuser-create").serialize()
});
request.fail(function(jqXHR, exception)
{
if(jqXHR.status === 500)
{
alert('Error interno:' + jqXHR.resposeText);
}
else if(jqXHR.status === 404)
{
alert('Pagina no encontrada[404]');
}
else if(exception === 'timeout')
{
alert('Error time out');
}
else if(exception === 'abort')
{
alert('Respuesta ajax abortada');
}
else
{
alert('Error no detectado '+jqXHR.responseText);
}
});
});
But It don´t go to the controller, don´t work, I received an Error 404 not found url
My call to the Controller
Route::Controller('users','UsersController');
the controller UserSController code
class UsersController extends BaseController
{
//metodo para agregar al usuario
public function postCreate()
{
//validamos reglas inputs
$rules = array(
'inputuser' => 'required|max:10',
'inputpassword' => 'required|min:8',
'inputpassword1' => 'required|min:8',
'inputemail' => 'required|email|unique:users'
);
$validation = Validator::make(Input::all, $rules);
//Si no pasa la validacion
if($validation->fails())
{
return Redirect::back()->with_input()->with_errors($validation);
}
//Si todo ha ido bien guardamos
$password = Input::post('inputpassword');
$user = new User;
$user->username = Input::post('inputuser');
$user->password = Hash::make($password);
$user->email = Input::post('inputemail');
$user->admin = Input::post('es_admin');
//guardamos
$user->save();
//redirigimos a usuarios
return Redirect::to('admin/users.index')->with('status','ok_create');
}
}
What am I doing wrong?