Ich habe eine Form, die eine Frist und der Benutzer enthält, den Termin in vier Eingabefelder wie folgt festgelegt:Laravel 5: Wie validate Datetime Eingabe von 4 Eingabefeldern?
<div class="form-group col-lg-3">
{!! Form::label('year', 'Year', ['class' => 'control-label']) !!}
{!! Form::selectYear('year',$year, $year +1, null , ['class' => 'form-control']) !!}
</div>
<div class="form-group col-lg-3">
{!! Form::label('month', 'Month', ['class' => 'control-label']) !!}
{!! Form::selectRange('month', 1, 12 , null , ['class' => 'form-control']) !!}
</div>
<div class=" form-group col-lg-3">
{!! Form::label('day', 'Day', ['class' => 'control-label']) !!}
{!! Form::selectRange('day', 1, 31 , null , ['class' => 'form-control']) !!}
</div>
<div class=" form-group col-lg-3">
{!! Form::label('hour', 'Hour', ['class' => 'control-label']) !!}
{!! Form::selectRange('hour', 6, 23 , null , ['class' => 'form-control']) !!}
</div>
In einem formRequest, ich bin diese vier Felder in eine Frist zu kompilieren. Also meine formRequest ist wie folgt:
public function rules()
{
$this->prepInput();
return [
];
}
public function prepInput(){
$input=$this->all();
...
$input['deadline']=$this->prepDeadline($input['hour'], $input['month'], $input['day'], $input['year']);
...
$this->replace($input);
}
public function prepDeadline($hour,$month,$day, $year){
$time = jDateTime::mktime($hour, 0, 0, $month, $day, $year);
return $deadline = strftime("%Y-%m-%d %H:%M:%S", $time);
}
Die Frist ist eine Jalali Datetime und ich muss überprüfen, ob der Benutzer ein gültiges Datum gewählt haben oder nicht (beispielsweise 1394.12.31 ist kein gültiges Datum). Das Paket hat eine checkdate
Methode, die genau wie php checkdate
funktioniert. Wo und wie kann ich das Datum in diesem Formular bestätigen und den Benutzer benachrichtigen, um ein gültiges Datum auszuwählen? In der Tat muss diese Validierung stattfinden, bevor die Frist an prepInput
übergeben wird.
Link-only-Antworten werden nicht als gute Praxis betrachtet, Sie sollten ein Beispiel in der Antwort selbst geben. – Petah