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

153
Vistas
after js validation and redir data is lost and not avalibale for php validation

Hi I cant figure out why it is not working I have simple form and want to validate in client side with simple xmlrequest redirect to other page, do there server validation and work with validated parametar. all in js vanila and pure php .

html:

<form  action=""  novalidate="novalidate" autocomplete="off"  id="name-group">
   <div class="form-group">
      <label for="number">*Number:</label>
      <input value="" type="text" name="number" id="number" class="form-control">
    </div>
     <input type="submit" value="Submit" name="submit" id="submit" class="btn btn-primary">
</form>

js validation:

document.getElementById("submit").addEventListener('click', function (event) {
    event.preventDefault();
    let number = document.getElementById("number").value;

    let numberRegex = "^[0-9]$";
    let errorMsg = '';
    if (number.match(numberRegex)) {
        let xhr = new XMLHttpRequest();
        let params = "number=" + number;
        xhr.open("POST", './uploadValidation.php',true)
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
        // xhr.onload = function () {
        // }
        xhr.send(encodeURI(params));
        window.location.assign('./uploadValidation.php')
    } else {
        errorMsg = 'required number field';
    }
    document.getElementById("errorMsg").innerHTML = errorMsg
});

after this I want to redirect to other page and do server validation

<?php

//errors
$errors = [
    'number' => '',
];
var_dump($_POST);
//validation
if (isset($_POST['submit'])) {
    $number = htmlentities(trim($_POST['number']), ENT_QUOTES, 'UTF-8');
    echo true;

    //check for error in userName field
    if (!$number || mb_strlen($number) < 1) {
        $form_valid = false;
        $errors['number'] = '*required field';
    }
}

?>

and the data is lost $_POST['number'] is not avalibale Please can some explain me why it is not working and how to fix?

EDIT: I Want to get input from user in first page and after js and php validation work with the input in second page.in my case add dynamicly inputs field (the number of fields = number from first user input).

about 4 years ago · Juan Pablo Isaza
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