I am working on the following code in the same PHP page. I am trying to instantly print the values of the form variables as soon as user hits submit button. However, I am seeing page getting refreshed with the following code. What would I need to do if I want to see the values instantly?
<form id = "myform" action="" method="post">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<button name = "submittest" type = "submit test">Submit Test </button>
</form>
<?php
if (isset($_POST['submittest'])) {
$example = $_POST['FirstName'];
$example2 = $_POST['LastName];
echo $example . " " . $example2;
}
?>
I have looked at some similar threads and haven't found what I am looking for :
1) Here they have suggested Ajax approach. I am trying to avoid it because I am having CORS issue while making ajax call.
2) Here again, ajax and target based approach which will take me to the new tab
3) Here in addition to Ajax, iFrame approach is suggested but not sure if that would give me what I am looking for because after getting the values of these variables, I am planning to convert all the values into a JSON object and call a Java webservice using curl. All of this I am doing to avoid javascript as I am encountering CORS issue.