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

258
Vistas
prompt window submits form no matter the if else check

I have integrated confirmation window to my Symfony form with javascript function.

This is my start form definition:

{{ form_start(form, {'attr': {'role': 'form', 'id':'editForm'} } ) }}

And in javascript:

$('#editForm').on('submit', function (e) {
e.preventDefault();
validateEditForm();
});

function validateEditForm()
{
    var nameInput;
    nameInput = prompt('Please input name to confirm edit:');
    var name = document.getElementById('edit_name').value;

if (nameInput === name || Number(nameInput) === name) {
    $('#editForm').submit();
} else if (nameInput === null || nameInput === "") {
    alert('You must enter name to confirm!');
    return false;
} else {
    alert("Entered name and default name don't match!");
    return false;
}

One case is not working.

When I enter correct name in the box then Please input workspace name to confirm edit: appears again. Then I click OK again and the form is submitted.. Is there something wrong with my if else checks?

Edit: Tried to do it in two separate functions and used e.preventDefault(); and the behaviour was the same.

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

0

I change validateEditForm method as returning boolean. On the form submit event, validateEditForm method decides whether submit the form or not.

$('#editForm').on('submit', function (e) {

    if(!validateEditForm()) {
         e.preventDefault();
    }
});

function validateEditForm()
{
    var nameInput;
    nameInput = prompt('Please input name to confirm edit:');
    var name = document.getElementById('edit_name').value;

if (nameInput === name || Number(nameInput) === name) {
    return true;
} else if (nameInput === null || nameInput === "") {
    alert('You must enter name to confirm!');
    return false;
} else {
    alert("Entered name and default name don't match!");
    return false;
}
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