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

464
Vistas
php isset($_post[]) and javascript form.submit

for some reason isset($_post) doesn't work when i use js form.submit() how i can resolve that without changing type of input from button to submit and just with using vanilla javascript because i need both of them.

code html:

<form name="user_verification" action="action.php" method="POST">
 Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="button" onclick="myFunction(this)" name="button" value="submit">
</form>

and here is the php script in action.php file

if($_SERVER['REQUEST_METHOD']=="POST")
{
if(isset($_POST['button'])) 
{
echo 'yes';
}else{
echo 'no';
}
}

and here is the javascript in action.js file

function myFunction(button)
{
//some code
const form=button.parentNode;
form.submit();}

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

0

Actually the problem didn't raise from the PHP. Buttons' value is sent when the form is directly submitted by them (In this case, it seems impossible).

Suggestion 1: use another field to check form submission.

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    if(isset($_POST['email'])) {
        echo 'yes';
    } else {
        echo 'no';
    }
}

Suggestion 2: add hidden input in the HTML.

<form name="user_verification" action="test.php" method="POST">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="hidden" name="button" value="submit">
    <input type="button" onclick="myFunction(this)">
</form>

Suggestion 3: change button type to hidden before submitting.

function myFunction(button) {
    // some code
    button.setAttribute('type', 'hidden');
    const form=button.parentNode;
    form.submit();
    button.setAttribute('type', 'button');
}
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