kingb00zer Posted November 17, 2011 Share Posted November 17, 2011 Hi I am trying to process a form which has 5 diferent submit options. Basically what I have is 1 text field where I enter a username and then I choose from 1 of 5 attack options. The problem is that with a basic html and php combo of code I cant assign each of the 5 php files to each of the submit buttons. I do reallise that I could put all 5 actions into the same file and run a switch however I already have over 800lines of code on just one and i hate scrolling through large ammounts of to find one line (dont we all?) After googling how to fix this issue I found something about using the javascript onclick thing (havnt really learned JS yet) this seems to be the kind of approach I want to take but dont know how to embed it into my code or weather I need to put any <script='javascript'> type of tags in my head. echo "<form method='post'><table class='target' width='150'>";echo "<tr><td align='left' colspan='1' class='one'>Target:</td><td align='left' colspan='1'> <input type='text' name='target' class='shortcuts' size='10' /></td></tr>";echo "</table>";echo "<table class='carjack' width='150'>";echo "<tr><td align='center' colspan='1' class='seven'>Carjacking</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: $thugs </td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='carjack.php';' /> </td></tr>";echo "</table>";echo "<table class='other' width='150'>";echo "<tr><td align='center' colspan='1' class='seven'>Other Minor Attack</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> to go</td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Here!' onclick='form.action='other.php';' /> </td></tr>";echo "</table>";echo "<table class='raid' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>House Invasion</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: </td><td align='left' colspan='1' class='one'> $thugs </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> AK47's: </td><td align='left' colspan='1' class='one'> $ak47a</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Pistols: </td><td align='left' colspan='1' class='one'> $pistola</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> </td><td align='left' colspan='1' class='one'> <br /></td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='houseinvasion.php';' /> </td></tr>";echo "</table>";echo "<table class='driveby' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>Driveby Shooting</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Thugs: </td><td align='left' colspan='1' class='one'> $thugs </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> AK47's: </td><td align='left' colspan='1' class='one'> $ak47a</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Pistols: </td><td align='left' colspan='1' class='one'> $pistola</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Escalades: </td><td align='left' colspan='1' class='one'> $escalade</td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='driveby.php';' /> </td></tr>";echo "</table>";echo "<table class='turfwar' width='150px'>";echo "<tr><td align='center' colspan='2' class='seven'>Turf War</td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Send: </td><td align='left' colspan='1'> <input type='text' name='amount' class='shortcuts' size='10' /></td></tr>";echo "<tr><td align='center' colspan='1' class='one'>Of:</td><td align='left' colspan='1'> <select class='shortcuts' name='drug'><option value='weed'>Weed</option><option value='xtc'>Ecstacy</option><option value='heroin' selected='selected'>Heroin</option> <option value='specialk'>Special K</option> <option value='acid'>Acid</option> <option value='coke'>Coke</option> </select> </td></tr>";echo "<tr><td align='center' colspan='1' class='one'> Price: $</td><td align='left' colspan='1'> <input type='text' name='price' class='shortcuts' size='10' /></td></tr>";echo "<tr><td align='center' colspan='2' > <input type='submit' value='Attack!' onclick='form.action='turfwar.php';' /> </td></tr>";echo "</table> </form> "; Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2011 Share Posted November 17, 2011 Without relying on Javascript, one single form element can only send data to one single file. You could have all the actions in one file that includes other files: if(!empty($_POST['something'])) { // The submit button with name "something" was clicked include 'something.php';} else if(!empty($_POST['somethingelse'])) { // The submit button with name "something" was clicked include 'somethingelse.php';} Each submit buton has to have a name attribute that will identify it. Link to comment Share on other sites More sharing options...
kingb00zer Posted November 17, 2011 Author Share Posted November 17, 2011 hmm I didnt think of using include. When another php file is included that simply means that php file is run when that line of code is read right? (I use it for my connection but dont fully understand it)Also I am happy to rely on javascript, just dont fully understand it either yet.EDIT: Thank you I got it to work and learned more about include Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2011 Share Posted November 17, 2011 An included file, no matter what the content is, will be parsed like a PHP file, that means that anything between <?php ?> blocks will be executed. I don't recommend relying on Javascript if you can manage exactly the same thing without it. Not everybody has Javascript enabled in their browsers, though most people do. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.