• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

244
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>
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error