I want to use dropzone.js to upload images in my application , I'm using laravel 4.2 , This is my code in the view :
{{ Form::open(array('class'=>'dropzone', 'id'=>'my-awesome-dropzone' ,'files'=> true , 'method' => 'post' ,'route' => '/')) }}
<div class="form-group">
{{ $errors->first('title','<div class="alert alert-danger" role="alert">:message</div>') }}
{{ Form::text('title',null , array('placeholder'=>'title' , 'class' => 'form-control')) }}
</div>
<div class="form-group">
{{ $errors->first('image','<div class="alert alert-danger" role="alert">:message</div>') }}
{{ Form::label('image', 'Image') }}
{{ Form::file('image') }}
</div>
{{ Form::submit('create' , array('class' => 'btn btn-default')) }}
{{ Form::close() }}
And this is my code to upload image in the controller
if (Input::hasFile('image'))
{
$file = Input::file('image');
$timestamp = (new DateTime)->getTimestamp();
$imageFileName = Helpers::getFriendlyURL(Input::get('title'),$timestamp) .'.png';
$file->move('uploads/'. Auth::user()->id .'/', $imageFileName);
$image = Image::make(sprintf('uploads/'. Auth::user()->id .'/%s', $imageFileName))->fit(900, 300)->save();
}
I have 2 Qestions :
1 - How to change the default file name 'file' of dropzone to 'image' ?
2 - the submit button comes on and the browse button appears ?
Related
How to pass attributes like id, class to form model?
This what i try not working and in official Laravel documentation wass not defined.
#if(isset($country))
{{ Form::model($country, ['route' => ['country.show', $country->id]], ['class' => "123"]) }}
#else
{{ Form::open(['route' => 'country.store', 'id'=> 'admin_store_form' ]) }}
#endif
<div class="row mb-2">
<div class="col-sm-1">
{{ Form::label('name', 'Name', ['class' => 'col-sm-2 admin-label col-form-label']) }}
</div>
<div class="col-sm-3">
{{ Form::text('name', old('name'), ['placeholder'=>'Name', 'class' => 'form-control form-control-sm admin-control']) }}
</div>
</div>
{{ Form::close() }}
I define 'class' => "123" but that not work.
The correct way to add a class to Form::model is:
{{ Form::model($country, ['route' => ['country.show', $country->id], 'class' => '123']) }}
You need to add the class key to the same array argument as route.
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 ?
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>
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>
First of all sorry for my bad english.
I have a laravel form using blade template engine that show me an exception error. If i remove the code and use the php form with echo statmente everything fine and the page show up.
where is the problem? Here is my code
{{ HTML::ul($errors->all()) }}
{{ Form::open(array('url' => 'news')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::title('name', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::text('email', Input::old('description'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Create the Nerd!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
There is no such thing as Form::title() in laravel.
Try this
{{ HTML::ul($errors->all()) }}
{{ Form::open(array('url' => 'news')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::text('name', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::text('email', Input::old('description'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Create the Nerd!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
Make sure you figure these errors yourself as these are typing mistakes.