Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!