2

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.

Dan
  • 443
  • 1
  • 7
  • 19
  • _instantly print the values of the form variables_ Where are you trying to print these values? – RiggsFolly Mar 17 '18 at 00:22
  • Here `echo $example . " " . $example2;` ? – Dan Mar 17 '18 at 00:41
  • So what does not work about what you have done – RiggsFolly Mar 17 '18 at 00:59
  • @RiggsFolly To be specific I am developing a plug-in using this software `https://www.i2b2.org/webclient/`. We have shibboleth based authentication on that website. My php file is inside `webclient` folder. So whenever I try to hit a submit button it just logs me out of that application which I am assuming is happening because of the page refresh after clicking submit button. – Dan Mar 17 '18 at 01:08
  • If you submit a form without using Ajax, you're going to have a refresh. This is simply how web sites work. – Greg Schmidt Mar 17 '18 at 01:46
  • @GregSchmidt I see. On the other hand, do you think enabling CORS could be a security threat? – Dan Mar 17 '18 at 01:58
  • Nothing about what you've posted so far explains why you would need CORS. You've said something about an assumption you're making about the log out issue. Maybe create a new question to solve that problem instead of trying to add workarounds on top of workarounds? – Greg Schmidt Mar 17 '18 at 16:22

0 Answers0