Jump to content

c++ coder having conceptual problems...


Derleek

Recommended Posts

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...

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.