Jump to content

[SOLVED] Multiple Submits on one page


cry of war

Recommended Posts

Im trying to get a form to work on a admin page Im making for my game. I know how to make the php register a single form on a page and bring its self back to the same page but i was wondering how do I make it so a person can subit the different froms with out making multiple pages of php and linking them through the action tag.

 

this is the php code i have so far where it goes from he depends on how the coding goes so it really basic for right now.

 

<html>
<?php 
$add="adminadded.php"
?>
<title>Admin Edit</title>
<body>
<h3> Welcome Admin </h3>
Manipulate Player Stats
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="manipulate" name="Update" />
</form>
Add/Delete Weapon
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="weapon" name="Update" />
</form>
Add/Delete Skill
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="skill" name="Update" />
</form>
Add/Delete Feat
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="feat" name="Update" />
</form>
Add/Delete Monster
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="monster" name="Update" />
</form>
Add/Ban/Delete User
<form action="<?php echo $add ?>" method="post">
<input type="submit" value="user" name="Update" />
</form>
</body>
</html>

Link to comment
Share on other sites

I have a few friends that are going to help me with a game and this page is going to be set up so they can insert information directly into a db so that others can use the information on the game. more of a way to let them help me but not mess up my db and tables too badly

Link to comment
Share on other sites

There is no reason to use multiple forms, that I can think of.

 

You accomplish what you are trying to do with all that code the same, but only one form and changing the names of the submit buttons. Instead of one common name, give them the same name as the value (or whatever name you want, but all different). When you click a submit button that is named, that name is put into the $_POST array (or $_GET) so all you have to do is something like:

if (isset($_POST["manipulate"])
  \\manipulate something!
else if (isset($_POST["weapon"])
  \\weapon something?

 

etc.

Link to comment
Share on other sites

Perhaps an example?

 

<?php
if(isset($_POST['submit1'])){
echo 'You clicked the first submit button!';
}elseif(isset($_POST['submit2'])){
echo 'You clicked the second submit button!';
}else{
echo 'You havn\' pressed a button yet';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" />
<input type="submit" name="submit1" value="Click Me!" /><br />
<input type="submit" name="submit2" value="No, Click Me!" />
</form>

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.