Derleek Posted May 6, 2008 Share Posted May 6, 2008 Hi, i'm new to the world of coding for the web. I have a good amount of C++ experience... but i'm having trouble conceptualizing how the best way to handle variables from one page to another. For example, if i am creating a game and i want to validate the input. Is there a way to handle the html form on that same page that they input it? ok so basically can i take this basic form handling script.... Form: <form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> welcome.php: <html> <body> Welcome <?php echo $_POST["name"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html> and make it do something like this... welcome.php: <html> <body> <form action="randomFunction()" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> <?php function randomFunction() { //validate input } ?> </body> </html> I'm really asking this for efficiency sake... I'm wondering if the best approach is to create a temporary MySQL table then validate using a separate php script, proceed to store the data permanently... so if that doesn't make any sense, what is the best method to receive user input/validate and store using MySQL... Quote Link to comment Share on other sites More sharing options...
conker87 Posted May 6, 2008 Share Posted May 6, 2008 Functions made in PHP must be called through PHP. If you want to do what you're suggesting, set the action to the same page, name the submit button something and do: <html> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" name="submit_1" /> </form> <?php if ($_POST['submit_1']) { // validate } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted May 6, 2008 Share Posted May 6, 2008 Id say do everything on the same page e.g. <form action="post"> <input type="text" name="nametext"> <input type="submit" name="submitbtn"> </form> <? if (strip_tags($_POST['nametext']) && strip_tags($_POST['submitbtn'])){ //validation etc here } ?> This way the user doesnt have to go from page to page to page. Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 6, 2008 Author Share Posted May 6, 2008 makes total sense, i feel silly for asking Quote Link to comment Share on other sites More sharing options...
Derleek Posted May 6, 2008 Author Share Posted May 6, 2008 makes sense... cool thanks Quote Link to comment 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.