Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cotations88's avatar

submit register form with dropdown input birth_date.

I replaced a datepicker input with 3 select inputs.day-month-year. Currently I am having trouble sending the data to the database.

<div class="row">
                      <p class="birth"><strong>Date of Birth</strong></p>
                      <div class="form-group col-sm-3 col-xs-6">
                     <label for="day"class="sr-only"></label>
                      <select name="day" id="day" value="day">Day:</select>
                      @error('day')<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong> </span> @enderror
                      </div>
                      <div class="form-group col-sm-3 col-xs-6">
                        <label for="month" class="sr-only">Month:</label>
                      <select name="month" id="month" value="month"></select>
                      @error('month')<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong> </span> @enderror
                      </div>
                      <div class="form-group col-sm-6 col-xs-6">
                        <label for="year" class="sr-only">Year:</label>
                      <select name="year" id="year" value="year">Year:</select>
                      @error('year')<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong> </span> @enderror
                    </div>
                    </div>             

Model User

 protected $fillable = [
        'first_name',
        'last_name',
        'email',
        'password',
        'birth_date',
        'gender',
        'slug',
        'day',
        'month',
        'year '

My Register Controller

public function register(Request $request)
    {
        $request->validate([
            
            'first_name' => ['required', 'string', 'max:255'],
             'last_name' => ['required', 'string', 'max:255'],
             'gender' => ['required', 'in:male,female'],
             'birth_date' => ['required', 'date', 'max:15'],
             //'day' => ['required', 'date', 'max:15'],
             //'dob' => ['required', 'date', 'max:15'],
             //'month' => ['required', 'date', 'max:15'],
             //'year' => ['required', 'date', 'max:15'],
             
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
  

       // $dob =  str_slug($request['day'].'-'.$request['month'].'-'.$request['year'],'-');
         $birth_date = $request['day']."-".$request['month']."-".$request['year'];
           // $dob = Carbon\Carbon::createFromFormat('day/month/year');
        $user = new User;
        $user->first_name = $request->first_name;
        $user->last_name = $request->last_name;
        $user->email = $request->email;
       //$user->day = $request->day;
     //   $user->month = $request->month;
     //   $user->year = $request->year;
        $user->password = Hash::make($request->password);
        $user->slug = str_slug($request['first_name'].'-'.$request['last_name'],'-');
        $user->birth_date = $request['day']."-".$request['month']."-".$request['year'];
      
$user->save();

}

0 likes
6 replies
cotations88's avatar

@Hasnainali9 l am using javascript with theses inputs. l don't want to use date or time picker again. My problem is sending my form in database. With datepicker everything work fine, but with select input and javascript , l get nothing in my Db after submitting my form.

Snapey's avatar

@cotations88 use the select properly, with options. Also remove the value="day" etc from the select.

remove Day: from inside the select element and replace it with the options.

Use the old() helper to set the selected value after a validation error.

1 like
tangtang's avatar

@cotations88

is this birth_date column type in database is type date ? if so you should change the order of this select option request in controller from dd-mm-yyyy to yyyy-mm-dd

this is the reference

 $user->birth_date = $request['year']."-".$request['month']."-".$request['day'];

and make sure this select option have the value, you can check it in console or dd it in controller.

cotations88's avatar

@tangtang Thanks for your help ,l use this successfully $user->birth_date = \Carbon\Carbon::parse($request['year']."-".$request['month']."-".$request['day']);

Snapey's avatar

unless you are converting the 3 fields into one in javascript, remove this validation rule

         'birth_date' => ['required', 'date', 'max:15'],
1 like

Please or to participate in this conversation.