olamideX Newbie
Posts: 3
Threads: 1
Joined: Oct 2019
Reputation:
0
10-30-2019, 03:12 AM
(This post was last modified: 10-30-2019, 03:39 AM by ciadmin .)
I have a form with fields that I have hidden with a drop down function, but I want the fields when displayed alone to require all fields to be completed.
I have tried to set required attribute at the controller page and also on the form page, but it will require that the user fills out the field even if it is visible or not:
please find below my code and i want to make all fields for Education 1 and 2 required when the drop down is selected and open on the form
**EDITED** [ c o d e ] tags added to preent TL/DR
Code:
<legend>Education:</legend>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree">Year Of Degree *:</label>
<div class="col-sm-9">
<select name="Year_of_Degree" class="Year_of_Degree form-control fstdropdown-select" id="Year_of_Degree">
<option value="" <?php echo set_select('Year_of_Degree', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree">Class Of Degree *:</label>
<div class="col-sm-9">
<select name="Class_of_Degree"class="Class_of_Degree form-control required" id="Class_of_Degree">
<option value="" <?php echo set_select('Class_of_Degree', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Institution">Institution *:</label>
<div class="col-sm-9">
<select name="Institution" class="Institution form-control fstdropdown-select" id="Institution">
<option value="" <?php echo set_select('Institution', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('Institution', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type">Degree Type *:</label>
<div class="col-sm-9">
<select name="Degree_Type"class="Degree_Type form-control required" id="Degree_Type">
<option value="" <?php echo set_select('Degree_Type', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study">Course Of Study *:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study" placeholder="Course Of Study..." class="Course_of_Study form-control" id="Course_of_Study" value="<?php echo set_value('Course_of_Study', ''); ?>" >
</div>
</div>
<div id="qualification2" class="row-fluid">
<hr style="border: 1px solid #ccc;" />
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree1">Year Of Degree :</label>
<div class="col-sm-9">
<select name="Year_of_Degree1" class="Year_of_Degree1 form-control fstdropdown-select" id="Year_of_Degree1">
<option value="" <?php echo set_select('Year_of_Degree1', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree1', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree1">Class Of Degree:</label>
<div class="col-sm-9">
<select name="Class_of_Degree1"class="Class_of_Degree1 form-control required" id="Class_of_Degree1">
<option value="" <?php echo set_select('Class_of_Degree1', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree1', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree1', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree1', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree1', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree1', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree1', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree1', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree1', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree1', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree1', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="institution1">Institution:</label>
<div class="col-sm-9">
<select name="institution1" class="institution1 form-control fstdropdown-select" id="institution1">
<option value="" <?php echo set_select('institution1', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('institution1', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type1">Degree Type:</label>
<div class="col-sm-9">
<select name="Degree_Type1"class="Degree_Type1 form-control required" id="Degree_Type1">
<option value="" <?php echo set_select('Degree_Type1', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type1', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type1', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type1', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type1', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type1', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type1', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type1', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study1">Course Of Study:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study1" placeholder="Course Of Study..." class="Course_of_Study1 form-control" id="Course_of_Study1" value="<?php echo set_value('Course_of_Study1', ''); ?>" >
</div>
</div>
</div>
<div id="qualification3" class="row-fluid">
<hr style="border: 1px solid #ccc;" />
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Year_of_Degree2">Year Of Degree:</label>
<div class="col-sm-9">
<select name="Year_of_Degree2" class="Year_of_Degree2 form-control fstdropdown-select" id="Year_of_Degree2">
<option value="" <?php echo set_select('Year_of_Degree2', ''); ?> >-Select-</option>
<?php for($year = 2019; $year >=1970; $year--){ ?>
<option value="<?php echo $year?>" <?php echo set_select('Year_of_Degree2', $year); ?>><?php echo $year?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Class_of_Degree2">Class Of Degree:</label>
<div class="col-sm-9">
<select name="Class_of_Degree2"class="Class_of_Degree2 form-control required" id="Class_of_Degree2">
<option value="" <?php echo set_select('Class_of_Degree2', ''); ?> >-Select-</option>
<option value="First Class Honours" <?php echo set_select('Class_of_Degree2', 'First Class Honours'); ?> >First Class Honours</option>
<option value="Second Class Honours – Upper Division" <?php echo set_select('Class_of_Degree2', 'Second Class Honours – Upper Division'); ?> >Second Class Honours – Upper Division</option>
<option value="Second Class Honours – Lower Division" <?php echo set_select('Class_of_Degree2', 'Second Class Honours – Lower Division'); ?> >Second Class Honours – Lower Division</option>
<option value="Third Class Honours" <?php echo set_select('Class_of_Degree2', 'Third Class Honours'); ?> >Third Class Honours</option>
<option value="Distinction" <?php echo set_select('Class_of_Degree2', 'Distinction'); ?> >Distinction</option>
<option value="Upper Credit" <?php echo set_select('Class_of_Degree2', 'Upper Credit'); ?> >Upper Credit</option>
<option value="Lower Credit" <?php echo set_select('Class_of_Degree2', 'Lower Credit'); ?> >Lower Credit</option>
<option value="Merit" <?php echo set_select('Class_of_Degree2', 'Merit'); ?> >Merit</option>
<option value="Pass" <?php echo set_select('Class_of_Degree2', 'Pass'); ?> >Pass</option>
<option value="Fail" <?php echo set_select('Class_of_Degree2', 'Fail'); ?> >Fail</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="institution2">Institution:</label>
<div class="col-sm-9">
<select name="institution2" class="institution2 form-control fstdropdown-select" id="institution2">
<option value="" <?php echo set_select('institution2', ''); ?> >-Select-</option>
<?php if($institution_list){
foreach($institution_list as $institution){ ?>
<option value="<?php echo $institution->idinstitution?>" <?php echo set_select('institution2', $institution->idinstitution); ?>><?php echo $institution->institution?></option>
<?php }
}?>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Degree_Type2">Degree Type:</label>
<div class="col-sm-9">
<select name="Degree_Type2"class="Degree_Type2 form-control required" id="Degree_Type2">
<option value="" <?php echo set_select('Degree_Type2', ''); ?> >-Select-</option>
<option value="OND" <?php echo set_select('Degree_Type2', 'OND'); ?> >OND</option>
<option value="HND" <?php echo set_select('Degree_Type2', 'HND'); ?> >HND</option>
<option value="Associate’s Degree" <?php echo set_select('Degree_Type2', 'Associate’s Degree'); ?> >Associate’s Degree</option>
<option value="Bachelor’s Degree" <?php echo set_select('Degree_Type2', 'Bachelor’s Degree'); ?> >Bachelor’s Degree</option>
<option value="Master’s Degree" <?php echo set_select('Degree_Type2', 'Master’s Degree'); ?> >Master’s Degree</option>
<option value="Professional Degree" <?php echo set_select('Degree_Type2', 'Professional Degree'); ?> >Professional Degree</option>
<option value="Doctorate Degree" <?php echo set_select('Degree_Type2', 'Doctorate Degree'); ?> >Doctorate Degree</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="Course_of_Study2">Course Of Study:</label>
<div class="col-sm-9">
<input type="text" name="Course_of_Study2" placeholder="Course Of Study..." class="Course_of_Study2 form-control" id="Course_of_Study2" value="<?php echo set_value('Course_of_Study2', ''); ?>" >
</div>
</div>
</div>
<div class="row-fluid text-right" id="degreeBtn1">
<input type="button" class="addDegree2" value="+ Add Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
<div class="row-fluid text-right" id="degreeBtn2">
<input type="button" class="addDegree3" value="+ Add Degree" />
<input type="button" class="removeDegree2" value="- Remove Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
<div class="row-fluid text-right" id="degreeBtn3">
<input type="button" class="removeDegree3" value="- Remove Degree" />
<hr style="border: 1px solid #ccc;" />
</div>
Attached Files
agreement.php (Size: 62.85 KB / Downloads: 1)
Main_model.php (Size: 11.74 KB / Downloads: 1)
Agreement_ctrl.php (Size: 8.49 KB / Downloads: 2)
olamideX Newbie
Posts: 3
Threads: 1
Joined: Oct 2019
Reputation:
0
(10-30-2019, 08:49 AM) php_rocs Wrote: @olamideX ,
When the field is not visible are you correctly making it not mandatory or setting a default value for it?When the field it's not visible, the value is null but I want it to be required when it is visible
Wouter60 Posting Freak
Posts: 851
Threads: 38
Joined: Feb 2015
Reputation:
77
Create validation rules only for fields that are visible.
E.g. field10 and field11 are only visible if field4 has a value:
PHP Code:
if ( $this -> input -> post ( 'field4' )) { $this -> form_validation -> set_rules ( 'field10' , 'Field 10' , 'required' ); $this -> form_validation -> set_rules ( 'field11' , 'Field 11' , 'required' ); }
olamideX Newbie
Posts: 3
Threads: 1
Joined: Oct 2019
Reputation:
0
(10-30-2019, 02:03 PM) Wouter60 Wrote: Create validation rules only for fields that are visible.
E.g. field10 and field11 are only visible if field4 has a value:
PHP Code:
if ( $this -> input -> post ( 'field4' )) { $this -> form_validation -> set_rules ( 'field10' , 'Field 10' , 'required' ); $this -> form_validation -> set_rules ( 'field11' , 'Field 11' , 'required' ); }
Hello Wouter, i want the fields when visible to take up the attribute to be required , i know how to implement the required form on controller form but if i set this for all the fields, it will require it if it is visble or not