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>