Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
How to activate javascript code on form validation with php

How to activate javascript code on form validation.

I am running form validation on a combined (visually) login/register form. The login form is displayed by default and the register form is displayed when a user clicks a button and the following js code is run

var card = document.getElementById("card");
      function openRegister() {
        card.style.transform = "rotateY(-180deg)";
      }
      function openLogin() {
        card.style.transform = "rotateY(0deg)";
      }

Which all works fine, the problem comes when I run the form validation using php. The error reporting works, and the error messages displayed in the correct location. So, error message for the login form is displayed in a div with a class of card-front, and the registration form error is in a div with a class of card-back.

So the system works fine when the user uses the login page, which is shown by default, the issue arises when the user uses the register form because the header(“location:loginRegForm.php”) shows the default login form. If the button is clicked to show the register form the correct error message is displayed.

So, I need a way of triggering the above js code so if there is an error when using the register form the registration form is shown not the default login form. I have struggled with this for a few days so I would be grateful for any pointers

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Pass the error via $_SESSION or query parameter.

header("location:loginRegForm.php?regError=Custom errror message")

and then via javascript show the register form, es:

<script>
  if(document.location.href.indexOf('regError') > -1) {
     openRegister();
     var querystring = document.location.href.split('?').pop().split('&');
     for(var qs, qsi = 0; qsi < querystring.length; qsi++) {
       qs = querystring[qsi].split('=');
       if(qs[0] === 'errorMsg') {
          document.queryString('.regErrorBlock').innerText = qs[1];
          document.queryString('.regErrorBlock').style.display = 'block';
          break;
       }
     }
  }
</script>

inside the register form add this block to show the error

<div class="regErrorBlock" style="display:none"></div>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda