in my blade i have this change password function i wanted it to "display" the old password when the user have errors like for example the user entered nothing and clicked submit so here is the code in my blade
<div class="form-group">
{{ Form::label('cpass', 'Current Password') }} <span style="color:red"><i>{{ $errors->first('cpass', ':message') }}</i></span>
{{ Form::password('cpass', array('class' => 'form-control' , 'placeholder'=>'enter current password') , Input::old('cpass') ) }}
</div>
<div class="form-group">
{{ Form::label('npass', 'New Password') }} <span style="color:red"><i>{{ $errors->first('npass', ':message') }}</i></span>
{{ Form::password('npass', array('class' => 'form-control', 'placeholder'=>'enter new password'), Input::old('npass') ) }}
</div>
<div class="form-group">
{{ Form::label('rpass', 'Re-type new Password') }} <span style="color:red"><i>{{ $errors->first('rpass', ':message') }}</i></span>
{{ Form::password('rpass', array('class' => 'form-control', 'placeholder'=>'re-type new password'), Input::old('rpass') ) }}
</div>
in my controller i throw it like this
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('User_Profile')
->withErrors($validator)
->withInput(Input::all());
}
else
{
//do stuff
}
i dont know why im not getting the old input from the user. what may be the wrong im doing? thanks
The form builder password method doesn't accept any input besides the name of the password field and its attributes:
http://laravel.com/api/4.2/Illuminate/Html/FormBuilder.html#method_password
You'll need to do this with javascript by setting the value of the password field manually on page load:
<script type="text/javascript">
$(function()
{
$('#rpass').val("{{ Input::old('rpass') }}");
});
</script>
Related
I'm new to laravel,i want to use the same form for add and edit.I created an form and form insertion is ok but i need to use the same form edit based on the id selected.When click the edit icon i want to direct the same page displaying the contents to edit.So give me idea for implementing this.
<form method="POST" action="/categoryinsert">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<div class="card-body">
<div class="form-group">
<div class="col-md-4">
<label for="exampleInputEmail1">Category</label>
<input type="text" class="form-control" name="category" id="category" placeholder="Enter Category">
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
// To create a new user in controller
public function create()
{
// user/createOrUpdate.blade.php view
return View::make('user.createOrUpdate');
}
// To update an existing user
public function edit($id)
{
$user = User::find($id);
// user/createOrUpdate.blade.php view
return View::make('user.createOrUpdate')->with('user', $user);
}
Add/edit in view with the help of user model
#if(isset($user))
{{ Form::model($user, ['route' => ['updateroute', $user->id], 'method' => 'patch']) }}
#else
{{ Form::open(['route' => 'createroute']) }}
#endif
{{ Form::text('fieldname1', Input::old('fieldname1')) }}
{{ Form::text('fieldname2', Input::old('fieldname2')) }}
{{ Form::submit('Save', ['name' => 'submit']) }}
{{ Form::close() }}
// To create a new user in controller
public function create()
{
// user/createOrUpdate.blade.php view
return view('user.createOrUpdate')->with([
'view_type' => 'create',
]);
}
// To update an existing user
public function edit($id)
{
$user = User::find($id);
// user/createOrUpdate.blade.php view
return view('user.createOrUpdate')->with([
'view_type' => 'edit',
'user' => $user
]);
}
<form action="{{ ( $view_type == 'edit' ? route('example', $id) : route('control.mentors.store')) }}" role="form" method="post" name="frmDetail">
I am using laravel 5 to create an edit form for a profile and can update picture in the form.
I want to store a new image in edit form. I use this code in edit.blade to get the image by user.
View:
{!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController#update', $dataItemregistration->ItemRegistrationID, 'files' => true] ]) !!}
<div class="form-group">
<div class="row">
<div class="col-lg-3">
{{ Form::label('pic', 'Gambar (Saiz gambar, 250x300px)') }}
</div>
<div class="col-lg-7">
{!! Form::file('gambar', array('class' => 'form-control')) !!}
</div>
</div>
</div>
<br>
<div class="col-lg-10 text-center">
{!! link_to(URL::previous(),'Back', ['class' => 'btn btn-warning btn-md']) !!}
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
</div>
{!! Form::close() !!}
Controller:
public function update(Request $request, $id)
{
$valueitemregistrations = Itemregistration::find($id);
$this->validate($request,['gambar' => 'max:100000',]);
if ($request->hasFile('gambar')) {
// Get the file from the request
$file = $request->file('gambar');
// Get the contents of the file
$content = $file->openFile()->fread($file->getSize());
$valueitemregistrations->Picture = $content;
$valueitemregistrations->update();
if($valueitemregistrations) {
return redirect('profil');
} else {
return redirect()->back()->withInput();
}
} else {
echo "testing";
}
}
When I try to upload and update, it goes to echo "testing". It doesn't detected any files uploaded..
I had been using the same code for add.blade and it works.
Is it related to route path or else?
This happens when your HTML form doesn't have enctype="multipart/form-data".
In this case the cause is 'files' => true being part of the wrong array inside Form::model(); it's inside the 'action' array when it should be outside. Try this:
Form::model($dataItemregistration, [
'method' => 'PATCH',
'action' => ['Modul\ProfilController#update', $dataItemregistration->ItemRegistrationID],
'files' => true,
]);
I'm using Jquery Datatable for a small project along with Laravel 5.6,
one of the datatable columns allows to edit a specific row , (by the way, I'm not using datatable editor plugin which has to be adquired).
the modal window contains the update form with the jquery logic, when i click update i don't see the updated row changes on datatable.
modal window to update datatable row
modal window code:
<div class="row padded">
<div class="col-md-12">
<div class="form-group">
</div>
{!! Form::open([ 'route' =>['srh.prestamo_pago.update', $prestamo_pago->id] ,'method' => 'PUT', 'id' => 'frmEdit_pago']) !!}
<div class="form-group">
{{ Form::label('Nro Cuota', 'Nro Cuota') }}
{{ Form::text('nro_cuota', $prestamo_pago->nro_cuota, array('class' =>'form-control', 'required' =>'', 'max-length' => '50', 'id' => 'nro_cuota')) }}
</div>
<div class="form-group">
{{ Form::label('Monto Cuota', 'Monto cuota') }}
{{ Form::text('monto_cuota', $prestamo_pago->monto_cuota, array('class' =>'form-control', 'required' =>'', 'max-length' => '50','id' => 'monto_cuota', "readonly" )) }}
</div>
<div class="form-group">
{{ Form::label('Fecha Pago', 'Fecha Pago') }}
#if(isset($prestamo_pago->fecha_pago))
{{ Form::text('fecha_pago', date("d/m/Y", strtotime($prestamo_pago->fecha_pago)) , array('class' =>'form-control datepicker1', 'required' =>'', 'max-length' => '50','id' => 'fecha_pago')) }}
#else
{{ Form::text('fecha_pago', null , array('class' =>'form-control datepicker1', 'required' =>'', 'max-length' => '50','id' => 'fecha_pago')) }}
#endif
</div>
<div class="form-group">
{{ Form::label('Fecha Vencimiento', 'Fecha Vencimiento') }}
{{ Form::text('fecha_vencimiento', date("d/m/Y", strtotime($prestamo_pago->fecha_vencimiento)), array('class' =>'form-control', 'required' =>'', 'max-length' => '50','id' => 'fecha_vencimiento', 'readonly'=>'')) }}
</div>
<div class="form-group">
{{ Form::label('Seleccione', 'Seleccione Estado') }}
{{ Form::select('estado_cuota', array( 'CANCELADO' =>'CANCELADO', 'PENDIENTE' =>'PENDIENTE'), $prestamo_pago->estado_cuota, array('class' =>'form-control', 'required' =>'', 'id' => 'estado_cuota'))}}
</div>
<div class="form-group">
{{ Form::label('Tipo Asiento', 'Tipo Asiento') }}
<input name="tipo_asiento" type="text" value="{{ $prestamo_pago->tipo_asiento_ingreso }}" id="tipo_asiento" class="form-control" readonly="readonly">
</div>
<div class="form-group">
{{ Form::label('Tipo Obligacion', 'Tipo Obligacion') }}
<input name="tipo_obligacion" type="text" value="{{$prestamo_pago->tipo_obligacion_ingreso}}" id="tipo_obligacion" class="form-control" readonly="readonly">
</div>
<div class="form-group">
{{ Form::label('Codigo Cuenta', 'Codigo Cuenta ') }}
{{ Form::text('cod_cuenta', $prestamo_pago->cod_cuenta, array('class' =>'form-control', 'required' =>'', 'max-length' => '50','id' => 'cod_cuenta','readonly'=>'')) }}
</div>
<div class="form-group">
{{ Form::label('Observación')}}
{{ Form::textarea('glosa', null,
array('class' => 'form-control',
'id' => 'glosa',
'size' => '30x3',
'required' => '',
'placeholder' => 'Ingrese Observación')) }}
</div>
<div class="form-group">
{{ Form::hidden('id_cuota', $prestamo_pago->id, array('id' => 'id_cuota')) }}
{{ Form::hidden('estado_final_cuotas','', array('id' => 'estado_final_cuotas')) }} // SI SE HAN CANCELADO TODAS LAS CUOTAS
{{ Form::hidden('prestamo_solicitud_id', $prestamo_pago->prestamo_solicitud_id, array('id' => 'prestamo_solicitud_id')) }}
{{ Form::hidden('nro_obligacion', '', array('id' => 'nro_obligacion')) }}
{{ Form::hidden('nro_asiento', '', array('id' => 'nro_asiento')) }}
{{ Form::hidden('contracuenta','', array('id' => 'contracuenta')) }}
{{ Form::submit('Actualizar Pago', array('class' => 'btn btn-primary btn-block', 'style' => 'margin-top:20px')) }}
</div>
{!! Form::close() !!}
</div>
</div>
<script type="text/javascript">
$(function(){
// FORM DATA AND HIDDEN FORM FIELDS
$('#frmEdit_pago').on('submit', function(e){
e.preventDefault();
var id = $('#id_cuota').val();
var tipo_asiento = $('#tipo_asiento').val();
var tipo_obligacion = $('#tipo_obligacion').val();
var cuenta_ingreso = $('#cod_cuenta').val();
var nro_cuota = $('#nro_cuota').val();
var prestamo_solicitud_id = $('#prestamo_solicitud_id').val();
var estado_cuota = $('#estado_cuota').val();
//pass search params and get data from database , then load hidden form fields
$.get('prestamo_pago/get_datos_contables',
{
'tipo_obligacion':tipo_obligacion,
'tipo_asiento': tipo_asiento,
'cuenta_ingreso' : cuenta_ingreso,
'nro_cuota' : nro_cuota,
'prestamo_solicitud_id' : prestamo_solicitud_id,
},
function(data) {
console.log(data);
$('#nro_obligacion').val(data.nro_obligacion);
$('#nro_asiento').val(data.nro_asiento);
$('#contracuenta').val(data.contracuenta.contracuenta_gasto);
var frm = $('#frmEdit_pago')[0];
var send = $(frm).serializeArray();
$.post(frm.action, send,
function(data) {
console.log(data);
//*****************************************************************
Here i want to refresh datatable to display updated row, I get datatable1.rows.data is not a function error, i think it doesn't get the instance of the main window.
datatable1.clear().draw();
datatable1.rows.data(data.cuotas_prestamo).draw();
//******************************************************************
toastr.success('Se ha guardado la información');
$('#modal-pago').modal('hide');
},'json'
).fail(funFail);
},'json'
).fail(funFail);
});
});
PS.- the fact that I'm getting submit code in the modal window and not on the index.php that holds datatatable, is because I put hidden fields in the form and it has to be displayed for that to happen. maybe there's a way to pass datatable instance to the modal ?
I developed admin panel to add,edit,delete users in my website with Restfull Api. edit and delete work fine but add not.
when I add user it may work or this error may appear
The localhost page isn’t working
localhost is currently unable to handle this request.
This is my routes
Route::resource('admin/users','AdminUser');
This is store function in Admin user resource
public function store(Request $request)
{
//rules
$rules = array(
'name' => 'required',
'email' => 'required|email',
'password' => 'required|min:6|confirmed',
'password_confirmation' => 'required|min:6'
);
/*
validate the data user
**/
$validator = Validator::make($request->all(),$rules);
if ($validator->fails()) {
return view('admin.User.create_user')
->withErrors($validator)
->withInput(['page' => 'home']);
}
/*
Store the data user in the database
**/
$user = new User;
$user->name =$request->input('name');
$user->email = $request->input('email');
$user->password=bcrypt($request->input('password'));
$user->role='user';
$user->save(); //error here
//redirect
return redirect('admin/users')->with('message', 'Successfully added user!');
}
And this is create_user.blade.php
#extends('layouts.layout')
#section('content')
<section id="advertisement">
<div class="container">
<img src="{{asset('images/shop/advertisement.jpg')}}" alt="" />
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="left-sidebar">
#include('shared.sidebaradmin')
</div>
</div>
<div class="features_items"><!--features_items-->
<h2 class="title text-center">Add New Product</h2>
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
{{ Form::open(array('url' => 'admin/users')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::text('name',null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::email('email',null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('password_confirmation', 'Confirm Password') }}
{{ Form::password('password_confirmation', array('class' => 'form-control')) }}
</div>
{{ Form::submit('Add a new user !', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div><!--features_items-->
</div>
</div>
</section>
#endsection
hello i have this form and i have validations for it. I have already finished doing the validations for in inside my controller and i can already display the error messages in my view but i wanted the error message to be beside the input area where it came from
here is my code in the view
{{ Form::open(array('url' => 'addParentAccnt')) }}
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
</div>
<div class="form-group">
{{ Form::label('lName', 'Last Name') }}
{{ Form::text('lName', Input::old('lName'), array('class' => 'form-control','placeholder' => 'Insert Last Name')) }}
</div> {{ Form::submit('Proceed to Next Step', array('class' => 'btn btn-primary')) }}
{{ Form::close()}}
in the bottom of my view i added this code to display the error messages
#if ($errors->any())
<ul>
{{ implode('', $errors->all('<p style="color:red" class="error">:message</p>')) }}
</ul>
#endif
the code inside my controller is this
$rules = array
(
'username' => 'required|min:10|max:50',
'fName' => 'required|alpha|min:1|max:80',
'lName' => 'required|alpha|min:1|max:80',
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('createPa')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
//do something
}
Change your view as following:
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
{{ $errors->first('username', ':message') }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
{{ $errors->first('fName', ':message') }}
</div>