Welcome Guest, Not a member yet? Register   Sign In
form validation if checkbox is cheched
#1

(This post was last modified: 03-19-2020, 11:13 AM by pippuccio76.)

Hi , sorry for english , i have several row , in this row the first culumn is a checkbox , after there are other 6 field .
I must validate the form , if i select the checkbox the other field of row must be not empty .

The form is like this and is populate dinamically (not ever the same row) :

Code:
      <div class="table-responsive">
          <table class="table">

              <thead>
                <tr>
                  <th scope="col">  Componente </th>
                  <th scope="col">  Data Arrivo </th>
                  <th scope="col">  Ora Arrivo </th>
                  <th scope="col">  Data Partenza </th>
                  <th scope="col">  Ora Partenza </th>
                  <th scope="col">  Luogo Arrivo </th>
                  <th scope="col">  Mezzo  </th>
                </tr>
              </thead>
   


               
                <tr>
        <td>
        <div>
          <div class="form-check">
            <input name='id_media_club[1]' id="checkbox_1 " type="checkbox" value="3"
           
            >
            <label for="checkbox_1">ROSSI MARIO</label>
          </div>
        </div>
        </td>

          <td>
             <input  type='date'  value=''  id='id_class_data_arrivo_1'  class='form-control' name='data_arrivo[1]' maxlength='10'  >
          </td>


          <td>
           <input  type='time'  value=''  id='id_class_ora_arrivo_1'  class='form-control' name='ora_arrivo[1]' maxlength='10'  >
          </td>


          <td>
           <input  type='date'  value=''  id='id_class_data_partenza_1'  class='form-control' name='data_partenza[1]' maxlength='10'  >
          </td>




          <td>
           <input  type='time'  value=''  id='id_class_ora_partenza_1'  class='form-control' name='ora_partenza[1]' maxlength='10'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_luogo_arrivo_1'  class='form-control' name='luogo_arrivo[1]' maxlength='50'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_mezzo_arrivo_1'  class='form-control' name='mezzo_arrivo[1]' maxlength='50'  >
          </td>
        </tr>
         
                <tr>
        <td>
        <div>
          <div class="form-check">
            <input name='id_media_club[2]' id="checkbox_2 " type="checkbox" value="6"
           
            >
            <label for="checkbox_2">TOPOLINO PLUTO</label>
          </div>
        </div>
        </td>

          <td>
             <input  type='date'  value=''  id='id_class_data_arrivo_2'  class='form-control' name='data_arrivo[2]' maxlength='10'  >
          </td>


          <td>
           <input  type='time'  value=''  id='id_class_ora_arrivo_2'  class='form-control' name='ora_arrivo[2]' maxlength='10'  >
          </td>


          <td>
           <input  type='date'  value=''  id='id_class_data_partenza_2'  class='form-control' name='data_partenza[2]' maxlength='10'  >
          </td>




          <td>
           <input  type='time'  value=''  id='id_class_ora_partenza_2'  class='form-control' name='ora_partenza[2]' maxlength='10'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_luogo_arrivo_2'  class='form-control' name='luogo_arrivo[2]' maxlength='50'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_mezzo_arrivo_2'  class='form-control' name='mezzo_arrivo[2]' maxlength='50'  >
          </td>
        </tr>
         
                <tr>
        <td>
        <div>
          <div class="form-check">
            <input name='id_media_club[3]' id="checkbox_3 " type="checkbox" value="11"
           
            >
            <label for="checkbox_3">TERENCE HILL</label>
          </div>
        </div>
        </td>

          <td>
             <input  type='date'  value=''  id='id_class_data_arrivo_3'  class='form-control' name='data_arrivo[3]' maxlength='10'  >
          </td>


          <td>
           <input  type='time'  value=''  id='id_class_ora_arrivo_3'  class='form-control' name='ora_arrivo[3]' maxlength='10'  >
          </td>


          <td>
           <input  type='date'  value=''  id='id_class_data_partenza_3'  class='form-control' name='data_partenza[3]' maxlength='10'  >
          </td>




          <td>
           <input  type='time'  value=''  id='id_class_ora_partenza_3'  class='form-control' name='ora_partenza[3]' maxlength='10'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_luogo_arrivo_3'  class='form-control' name='luogo_arrivo[3]' maxlength='50'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_mezzo_arrivo_3'  class='form-control' name='mezzo_arrivo[3]' maxlength='50'  >
          </td>
        </tr>
         
                <tr>
        <td>
        <div>
          <div class="form-check">
            <input name='id_media_club[4]' id="checkbox_4 " type="checkbox" value="12"
           
            >
            <label for="checkbox_4">ROSSI SERENA</label>
          </div>
        </div>
        </td>

          <td>
             <input  type='date'  value=''  id='id_class_data_arrivo_4'  class='form-control' name='data_arrivo[4]' maxlength='10'  >
          </td>


          <td>
           <input  type='time'  value=''  id='id_class_ora_arrivo_4'  class='form-control' name='ora_arrivo[4]' maxlength='10'  >
          </td>


          <td>
           <input  type='date'  value=''  id='id_class_data_partenza_4'  class='form-control' name='data_partenza[4]' maxlength='10'  >
          </td>




          <td>
           <input  type='time'  value=''  id='id_class_ora_partenza_4'  class='form-control' name='ora_partenza[4]' maxlength='10'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_luogo_arrivo_4'  class='form-control' name='luogo_arrivo[4]' maxlength='50'  >
          </td>


          <td>
           <input  type='text'  value=''  id='id_class_mezzo_arrivo_4'  class='form-control' name='mezzo_arrivo[4]' maxlength='50'  >
          </td>
        </tr>
         

           </table>
          </div>
 
There is a way , because i can control but without form validation i cannot use set_value ...
Reply
#2

To know if a checkbox is checked it’s simple. If it is checked, the value is sent. If it is not checked, no value is sent. 

With this checkbox, if it is checked when you submit the form, in the controller you will get 3, if it is not, you will get NULL.

Code:
<input name='id_media_club[1]' id="checkbox_1 " type="checkbox" value="3">
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB