samedi 20 mars 2021

checking empty fields and redirecting with (header)

i am looking for an advice or a solution to my problem.(i am sorry for my english)

My problem is that i want to check html input fields and then deciding if to send the user to the main page or showing an error .

i searched over the internet and i found that i sould use js or jquery for this task, i dont know how to code with jquery so i used js here is my js code :

function verification(){

      action=document.getElementById('action').action;


      nom = document.getElementById('last_name').value;
      prenom = document.getElementById('first_name').value;
      birthday = document.getElementById('birthday').value;
      classe = document.getElementById('classe').value;
      email = document.getElementById('email').value;
      password = document.getElementById('password').value;
      subject = document.getElementById('subject').value;

      if (nom == "") {
        action="index.php";
      }
      else {
        action="../index.php";
      }
    }

and html code :

<form method="POST" action="../index.php" id="action">
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Prénom</label>
                                    <input class="input--style-4" type="text" name="first_name" id="first_name">
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Nom</label>
                                    <input class="input--style-4" type="text" name="last_name" id="last_name">
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Anniversaire</label>
                                    <div class="input-group-icon">
                                        <input class="input--style-4 js-datepicker" type="text" name="birthday" id="birthday">
                                        <i class="zmdi zmdi-calendar-note input-icon js-btn-calendar"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">La classe</label>
                                    <div class="p-t-10">
                                      <select name="classe" id="classe">
                                          <option disabled="disabled" selected="selected">Choisir</option>
                                            <option>(1ére année) System reseau informatique</option>
                                            <option>(1ére année) Gestion comptable</option>
                                            <option>(1ére année) Electro-technique</option>
                                              <option>(2éme année) System reseau informatique</option>
                                              <option>(2éme année) Gestion comptable</option>
                                              <option>(2éme année) Electro-technique</option>
                                      </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row row-space">
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Email</label>
                                    <input class="input--style-4" type="email" name="email" id="email">
                                </div>
                            </div>
                            <div class="col-2">
                                <div class="input-group">
                                    <label class="label">Mot de passe</label>
                                    <input class="input--style-4" type="password" name="password" id="password">
                                </div>
                            </div>
                        </div>
                        <div class="input-group">
                            <label class="label">Role</label>
                            <div class="rs-select2 js-select-simple select--no-search">
                                <select name="subject" id="subject">
                                    <option disabled="disabled" selected="selected">Choisir</option>
                                    <option>Professeur</option>
                                    <option>Etudiant</option>
                                    <option>Autre</option>
                                </select>
                                <div class="select-dropdown"></div>
                            </div>
                        </div>
                        <div class="p-t-15">
                            <button class="btn btn--radius-2 btn--blue"  onclick="verification()" type="submit">S'inscrire</button>
                        </div>
                    </form>

but the action doesnt change as required , and i dont what to do or what to learn to be honest , btw i am a beginner in php so if you found some faults in my code it will be so kind from you to report them.

Thanks for reading this and have a nice day




Aucun commentaire:

Enregistrer un commentaire