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
https://forums.phpfreaks.com/topic/66526-solved-multiple-submits-on-one-page/
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

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.

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>

Archived

This topic is now archived and is closed to further replies.

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