+ 2

How to submit a form to its self on sololearn?

I am try to get a user input and post it to the screen. Here is my code. <script> function validateForm() { var x = document.forms["NumInput"]["number"].value; if (isNaN(x) || x < 1 || x > 5) { alert("Please Enter A Number Between 1 And 5!"); return false; } } </script> <?php $CompNum = rand( 1,5); $UserNum = $_POST['number']; ?> <?php echo"Hello,", "<br/> " ,"Can you Guess the number your computer is thinking?","<br>"," Pick a number 1 - 5."; ?> <form name="NumInput" action='#' onsubmit="return validateForm()" method='post'>Enter Your Number:<input type='text' name='number'><input type="submit" value="Submit"> <br/> <?php echo "<br/>Your Number Is: " , $UserNum; if($UserNum == $CompNum){ echo"<br/><br/>You Win! Nice Job!"; echo"<br/>Your Computer's Number Is:" , $CompNum; }else{ echo"<br/><br/>Better Luck Next Time!"; echo"<br/>Your Computer's Number Is:" , $CompNum; } ?> any suggestions on how to do this if it is even possible on Sololearn. Thanks Everyone!

7th Mar 2017, 12:22 AM
Metrik 🕵
Metrik 🕵 - avatar
1 Réponse
+ 7
Code submitted to SoloLearn runs approximately 10s, once. There is no official saved state: You get 1 run, 1 output, and then everything this server knows about you app vanishes...so no form POSTing (no URL to use in any case). You could: 1. Submit separate code simulating a POST processor (same app + different input modes or separate apps) 2. Get a CodeAnywhere, AWS or Heroku box 3. Set up your own server (easier?: search for WAMP/LAMP premade virtual machines or dockers) 4. Try various Android apps (Termux, Android Servers Ultimate, PHP Server, ...) Otherwise the best approaches I've seen to interactivity include: 1. Python: Embedded steps (Ahri Fox): feeding the next choices to users as subsequent inputs for each run. You'd have to write your PHP this way (mode 1, mode 2, ...) 2. Web: Offloaded state (like Burey's games/apps). 3. I have ideas, but I'm being careful. I'll post if something's good. By the way: you can 'return false;' as part of onsubmit() to cancel the actual POST (stay in the app) while still processing code: onsubmit="doStuff(); return false;"
7th Mar 2017, 1:54 AM
Kirk Schafer
Kirk Schafer - avatar