LARAVEL styled password field with bootstrap - html

in this form i heve Form::password() and i can not styled or embeded class for that. for example this below class and style for Form::text can work correctly.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'UserName', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="username" class="form-control" type="text" name="username" placeholder="username">
but for Form::password() do not work:
{{ Form::password('password', null, array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="password" type="password" value="" name="password">

This will work:
{{ Form::password('password', array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
You don't need the null as you cannot specify a default value for password fields.

You can also use a custom HTML macro that enables the syntax similar to your first example.
See my answer here:
How to pass value to Password field in Laravel

This problem occurred when the null value in the password.
{!! Form::password('password', old('password'), ['class' => 'form-control ', 'placeholder' => 'Enter Password']) !!}
Please Remove the old('password'):
{!! Form::password('password', ['class' => 'form-control', 'placeholder' => 'Enter Password']) !!}

Related

How can I solve " Invalid datetime format: 1366 Incorrect integer value" Exception in Laravel 7?

I'm quite new to Laravel, I would like to update a column in mySQL database named "client_id" the name of the table is "projects" I would like to insert this column when a Client creates a new Project, because the project belongs to the Client who created it. "client_id" is the Primary Key (id) in the table called "clients". There is a relationship between "clients" table and "projects" table. I have written some code to solve this problem but I'm getting this Exception and the "client_id" column is not updated.
Please help.
Store Method in my Controller:
/**
* Store a newly created Project in storage.
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'description' => 'required|string|max:255',
'start_date' => 'required|date',
'start_time' => 'required|string|max:10',
]);
$project = Project::create([
'name' => $request->name,
'description' => $request->description,
'start_date' => $request->start_date,
'start_time' => $request->start_time,
]);
$loggedinId = Auth::id();
$project->update(['created_by' => $loggedinId]);
$userId = $loggedinId;
$clientId = Client::where('user_id', '=', $userId)->pluck('id')->all();
DB::table('projects')->where('created_by', '=', $loggedinId)->update([ 'client_id' => $clientId]);
return redirect()->back()->with('message', 'You have successfully submitted your Job Card');
}
Relationship in my Client Model:
/**
* #return HasMany
*/
public function projects()
{
return $this->hasMany(Project::class);
}
Relationship in my Project Model:
/**
* #return BelongsTo
*/
public function client()
{
return $this->belongsTo(Client::class, 'client_id');
}
Form In my Blade View:
<form method="POST" action="{{ route('client-jobcard.store') }}">
#csrf
<div class="form-group row">
<div class="col-sm-8">
<label for="name">{{ __('Job Card Name') }}</label><span class="required">*</span>
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="invalid-feedback">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<div class="col-sm-8">
<label for="description">{{ __('Job Card Description') }}</label><span class="required">*</span>
<textarea class="form-control{{ $errors->has('description') ? ' is-invalid' : '' }}" id="description" rows="4" style="height: 150px;" name="description" value="{{ old('description') }}" required autofocus></textarea>
#if ($errors->has('description'))
<span class="invalid-feedback">
<strong>{{ $errors->first('description') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
<label for="start_date">Start Date</label><span class="required">*</span>
<input type="date" class="form-control" id="start_date" name="start_date" value="{{ old('start_date') }}" required>
</div>
<div class="col-sm-4">
<label for="submission_date">Start Time</label><span class="required">*</span>
<input type="text" class="form-control" id="start_time" name="start_time" value="{{ old('start_time') }}" required>
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
<button type="submit" class="btn btn-primary">
{{ __('Submit') }}
</button>
</div>
</div>
</form>
This line:
$clientId = Client::where('user_id', '=', $userId)->pluck('id')->all();
will return a column, not the single ID ("2") that you want.
Then, when you assign it to client_id which is an integer, the ORM will render it as the string [2] instead of the number 2, and that will give you an error.
Either retrieve just the first tuple from Client, or extract $clientId[0] manually (wasteful and not recommended).
You also have a second error I had overlooked:
'created_by', '=', $loggedinId
The above means that created_by must be an integer value, but the text of the error implies SQL expects it to be a datetime. You seem to have a wrong definition in the database.
your time field is in string , it has to be changed , it is not the same format
can you try this instead

Laravel Form Builder datetime input

Is there a Laravel 5 Form Builder equivalent of HTML 5's datatime input field ? I have been searching all day but could not find any.
<input type="datetime-local" class="form-control" id="game-date-time-text" name="game_date_time">
Any help would be appreciated.
That worked
{{ Form::input('dateTime-local', 'game_date_time', $game->game_date_time, ['id' => 'game-date-time-text', 'class' => 'form-control']) }}

Blade Templating Input Type Value

In Html forms i can do this as like :
<input type="hidden" name="token" value="{{ $token }}">
I would like to do this in full blade templating like this :
{{ Form::hidden('token', $token, array('class' => 'form-control')) }}
But the second option doesn't pass the $token value. Where do i go wrong ?
-- UPDATE --
I have found the solution for this :
It is quite easy question, but had to be careful while naming the inputs in blade templating.
This is my first form, which is working nice :
<form action="{{ action('RemindersController#postReset') }}" method="POST">
<input type="hidden" name="token" value="{{ $token }}">
Email<input type="email" name="email">
Password<input type="password" name="password">
Password<input type="password" name="password_confirmation">
<input type="submit" value="Reset Password">
</form>
**In blade templating form it was like **
{{ Form::open(array('action' => 'RemindersController#postReset')) }}
{{ Form::hidden('token', $token , array('class' => 'form-control')) }}
{{ Form::email('email', null, array('class'=>'form-control input-sm','placeholder'=>'Mail address')) }}
{{ Form::password('pass', array('class'=>'form-control input-sm','placeholder'=>'New Password')) }}
{{ Form::password('pass_conf', array('class'=>'form-control input-sm','placeholder'=>'Confirm Password')) }}
{{ Form::submit('Submit', array('class'=>'btn btn-info btn-block')) }}
{{ Form::close() }}
--SOLUTION--
So the error is :
In 1st form,
Password<input type="password" name="password">
Password<input type="password" name="password_confirmation">
In 2nd form,
{{ Form::password('pass', array('class'=>'form-control
input-sm','placeholder'=>'New Password')) }}
{{Form::password('pass_conf', array('class'=>'form-control
input-sm','placeholder'=>'Confirm Password')) }}
input names are password and password_confirmation, and in the second form they are named pass and pass_conf.
I changed pass to password and pass_conf to password_confirmation and it's now working fine.
Thank you for your feedbacks and patience.
It's just a guess but you can try to put also static value:
{{ Form::hidden('token', 'some token here', array('class' => 'form-control')) }}
and now check if it is in page source.
If it's not it means that you probably redirect to form using withInput and then Larravel fills the form with the same data as previous even if you set value manually to any HTML form element.
In this case you could make redirection using:
->withInput(Input::except('token'));
If it's the case you can read more about it in this topic: Laravel redirection using withInput doesn't allow to change inputs values
EDIT
You should try to change:
return Redirect::back()->with('error', Lang::get($response));
into:
return Redirect::back()->with(array ('error', 'token'), array(Lang::get($response), Input::get('token'));

How to create a horizontal form in Phalcon

A very basic question. I studied the examples & tutorials like INVO & Vokuro provided by Phalcon. The Vokuro example uses forms but all the examples use vertical forms (one field below other). They use forms.render() function using volt template and the form itself. If I want to create Phalcon form with fields arranged in two or more columns, how do I do it. Is the only way to use html tables or is there some other way.
Here is code from Vokuro "Users form" example which creates a vertical form:
<div class="clearfix"> <label for="name">Name</label>
{{ form.render("name") }}
</div>
<div class="clearfix"> <label for="email">E-Mail</label>
{{ form.render("email") }}
</div>
<div class="clearfix"> <label for="profilesId">Profile</label>
{{ form.render("profilesId") }}
</div>
And corresponding form code is:
$name = new Text('name', array('placeholder' => 'Name' ));
$name->addValidators(array(
new PresenceOf(array('message' => 'The name is required'
)) ));
$this->add($name);
$email = new Text('email', array('placeholder' => 'Email' ));
$email->addValidators(array(
new PresenceOf(array('message' => 'The e-mail is required' )),
new Email(array( 'message' => 'The e-mail is not valid'
)) ));
$this->add($email);
$this->add(new Select('profilesId', Profiles::find('active = "Y"'), array(
'using' => array('id', 'name' ),.....some more code.......)));
This creates a form as given below:
Create a User
Name
[Text Box]
E-Mail
[Text Box]
Profile
[List Box]
If I try to use style="float:left" in the div tags, it doesn't help much neither removing them. I want a form like:
label: [input field] -gap- label: [input field]
label: [input field] -gap- label: [input field]
If space permits, create three columns instead of two as shown above.
Thanks
That is because they have every element in a separate div
<div class="clearfix"> <label for="name">Name</label>
{{ form.render("name") }}
</div>
<div class="clearfix"> <label for="email">E-Mail</label>
{{ form.render("email") }}
</div>
But you can arrange that any way you want. For example in one row:
<div class="clearfix">
<label for="name">Name</label>
{{ form.render("name") }}
<label for="email">E-Mail</label>
{{ form.render("email") }}
</div>
use it
<div class="form-group">
<label for="name">Name</label>
{{ form.render("name",['class': 'form-control']) }}
</div>
<div class="form-group">
<label for="email">Email</label>
{{form.render("email",['class': 'form-control'])}}
</div>

how to modify parameters like (style , class ..) in cakephp input?

in cakephp
echo $this->Form->input('email', array('type' => 'email'));
will render
<div class="input email">
<label for="UserEmail">Email</label>
<input type="email" name="data[User][email]" value="" id="UserEmail" />
how to make this like that
<input type="email" name="data[User][email]" value="" id="UserEmail" class="input_class" style="some:style;" />
Just add a "class" and/or "style" argument to your options array.
echo $this->Form->input('email', array('type' => 'email', 'class' => 'input_class', 'style' => 'some:style' ));
See the the FormHelper documentation for a list of all options.
if you need only input without lable you can also try in this way
echo $this->Form->input('email', array('type' => 'email','div'=>false, 'class' => 'input_class', 'style' => 'some:style' ));