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

351
Views
How show a confirmation message at php form submit which contains a dynamic message text?

I want to show a confirmation message at form submit with a confirmation message. Confirmation message itself needs to do some php calls in order to do some validations and then show a message with ok and cancel buttons. Upon pressing ok button, it should continue with submit flow and remain in the form otherwise.

I have taken following approach but it doesn't work. Even though it goes into else block it doesn't show the message. Seems like the second echo line is the problem. Can you give me a clue on how to accomplish this task?

PHP code:

<?php 
    if (!empty($_POST)){
        // read $_POST['item'] values and do the validation and construct validation message.
        // Because validation message is a dynamic one which is based on user inputs. 
        // Some server calls are also needs to make within this validation phase.
        
        if(empty($validation_msg)) {
            saveData();
        }
        else {
            echo '<script type="text/javascript"> if (confirm("' . $validation_msg . '")) { ';
            echo saveData(); 
            echo ' } </script>'; 
        }
    }
    
    function saveData(){
        // Save function goes here.
    }
?>

HTML code:

<div class="form-group">
    <button type="submit" class="btn btn-primary" id="submit_button" disabled><?= _('Save') ?></button>
</div>
about 4 years ago · Santiago Gelvez
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!