naik.tanmay28350843
naik.tanmay28350843

How to update data from radio buttons and checkboxes?

I have an application where I need the user to pick their gender in radio buttons. But it won't register in the database.

Here's the code on the page,

    <div class="col-sm-6">
            <h4>Gender</h4>
            <div class="radio">
                <input name="Gender" value="Male" type="radio"
                 {% if user.gender=="Male" %} checked="checked"{% endif %}
                 />
                <label for="Male">Male</label>
            </div>
            <div class="radio">
                <input name="Gender" value="Female" type="radio"
                 {% if user.gender=="Female" %} checked="checked"{% endif %}
                 />

Last updated

bpettis
bpettis

Are you using a custom user plugin? Or the rain lab user plugin?

The rain lab user plugin doesn't have a gender field you will have to extend the rain lab user plugin and make sure you also make those fields fillable. Then you can set the form to add those options.

If this is a custom plugin we need to look at your component.php or page php code to see why it isn't saving in the database.

naik.tanmay28350843
naik.tanmay28350843

bpettis said:

Are you using a custom user plugin? Or the rain lab user plugin?

The rain lab user plugin doesn't have a gender field you will have to extend the rain lab user plugin and make sure you also make those fields fillable. Then you can set the form to add those options.

If this is a custom plugin we need to look at your component.php or page php code to see why it isn't saving in the database.

I'm extending the Rainlab user plugin. Yes, I have made them fillable too. Here's the code,

public function boot()
    {

        UserModel::extend(function($model){
            $model->addFillable([
                'firstname',
                'lastname',
                'designation',
                'gender',
                'dob',
                'doj',
                'department'
            ]);
        });

        UsersController::extendFormFields(function($form, $model, $context){
            $form->addTabFields([
                ....]);}

The other values are saving and updating just fine. The if condition is also working

1-3 of 3