search

Home  >  Q&A  >  body text

The selected option is not saved in the form, but another option is stored

There are three options in the drop-down list:

  1. Deployed
  2. Not deployed
  3. has a problem

When I select "Deploy" it saves correctly. When I select "Not Deployed" it saves as "Fault" When I select "Faulty" it saves as "Faulty"

Can you please help me fix this issue so that the form is saved with only the selected options. Thanks.

</div>
                    </div>
                    <?php if(isset($vehicledetails[0]['v_is_active'])) { ?>
                    <div class="col-sm-6 col-md-3">
                      <div class="form-group">
                        <label for="v_is_active" class="form-label">Machinery Status</label>
                        <select id="v_is_active" name="v_is_active" class="form-control " required="">
                          <option value="">Select Machinery Status</option> 
                          <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==1) ? 'selected':'' ?> value="1">Deployed</option> 
                          <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==0) ? 'selected':'' ?> value="0">Not Deployed</option> 
                          <option <?php echo (isset($vehicledetails) && $vehicledetails[0]['v_is_active']==0) ? 'selected':'' ?> value="0">Faulty</option>
                        </select>
                      </div>
                    </div>
                  <?php } ?>

Can you please help me fix this issue so that the form is saved with only the selected options.

P粉851401475P粉851401475244 days ago518

reply all(1)I'll reply

  • P粉186017651

    P粉1860176512024-03-23 09:55:22

    I assume you have a $vehicledetails data array like

    $vehicledetails = array(
            array(
                'v_is_active' => 1
            )
        );

    So the problem with your code is that you are repeating the same condition for each of the three options.

    So if any condition is met, all options will appear checked.

    The conditions for each option should be updated to reflect the appropriate value in $vehicledetails[0]['v_is_active'].

    Additionally, the values ​​for the "Not Deployed" and "Faulted" options appear to be incorrect as they both have a value of 0.

    Modified code:

    
        

    Hope this helps.

    reply
    0
  • Cancelreply