k21chrono Posted November 23, 2009 Share Posted November 23, 2009 Like i want it to have a set of text boxes that the output values would appear in, for instance the submit button would call to a function or something that would generate a random number for each text box, i would love for it to do this without redirecting or refreshing the page if possible, even the littlest suggestions would help, thank you ahead of time. Quote Link to comment https://forums.phpfreaks.com/topic/182669-how-would-you-use-the-php-in-the-same-page-as-the-form/ Share on other sites More sharing options...
KevinM1 Posted November 23, 2009 Share Posted November 23, 2009 Like i want it to have a set of text boxes that the output values would appear in, for instance the submit button would call to a function or something that would generate a random number for each text box, i would love for it to do this without redirecting or refreshing the page if possible, even the littlest suggestions would help, thank you ahead of time. Well, there are two things in play - a sticky form to display the numbers on the same page as the form, and attempting to process the form without a refresh. A sticky form would look something like: <?php if(isset($_POST['submit'])) { //invoke random number functions } ?> <!DOCTYPE html> <html> <head> <title>Random number generator</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="text1" value="<?php if(isset($result1)) { echo $result1; } ?>" /> <br /> <input type="text" name="text2" value="<?php if(isset($result2)) { echo $result2; } ?>" /> <br /> <br /> <input type="submit" name="submit" value="Click to calculate random numbers" /> </form> </body> </html> This will cause the page to refresh itself when the submit button is clicked. If you want the values to appear without any refresh at all, you'd need to use AJAX. Another option is to forgo PHP completely and use JavaScript only. But, since you asked this in the PHP Coding section, I figured you wanted to see your PHP options. Quote Link to comment https://forums.phpfreaks.com/topic/182669-how-would-you-use-the-php-in-the-same-page-as-the-form/#findComment-964118 Share on other sites More sharing options...
k21chrono Posted November 23, 2009 Author Share Posted November 23, 2009 This will cause the page to refresh itself when the submit button is clicked. If you want the values to appear without any refresh at all, you'd need to use AJAX. Well I am kind of new to this whole thing so I'll have to look up into the whole AJAX thing but if you want you can tell me how, otherwise if i run into trouble I'll post a follow up question, thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/182669-how-would-you-use-the-php-in-the-same-page-as-the-form/#findComment-964122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.