Darkmatter5 Posted June 12, 2009 Share Posted June 12, 2009 Here's my php <form method="post"> <input type="hidden" name="page" value="2"> <table> <tr> <td align="right"><label for="abil_str">Str: </label></td> <td><input type="text" name="abil_str" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='strength'"),0,50); ?></td> </tr> <tr> <td align="right"><label for="abil_dex">Dex: </label></td> <td><input type="text" name="abil_dex" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='dexterity'"),0,50); ?></td> </tr> <tr> <td align="right"><label for="abil_dex">Con: </label></td> <td><input type="text" name="abil_con" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='constitution'"),0,50); ?></td> </tr> <tr> <td align="right"><label for="abil_dex">Int: </label></td> <td><input type="text" name="abil_int" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='intelligence'"),0,50); ?></td> </tr> <tr> <td align="right"><label for="abil_dex">Wis: </label></td> <td><input type="text" name="abil_wis" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='wisdom'"),0,50); ?></td> </tr> <tr> <td align="right"><label for="abil_dex">Cha: </label></td> <td><input type="text" name="abil_cha" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='charisma'"),0,50); ?></td> </tr> <tr><td colspan="2" align="center"><input type="submit" name="reroll" value="Reroll"> <input type="submit" name="submit" value="Submit"></td></tr> </table> </form> Now the reroll button works like this, but what if I want to submit the rolls to a script as the form action? If I include the following code "<form method="post" action="scripts/pcb.php">" it breaks the roll button. How can I get both to work within this form? Thanks! Quote Link to comment Share on other sites More sharing options...
Darkmatter5 Posted June 12, 2009 Author Share Posted June 12, 2009 No ideas yet? Quote Link to comment Share on other sites More sharing options...
waynewex Posted June 12, 2009 Share Posted June 12, 2009 Firstly: Try not to mix your logic with your presentation. It makes it a nightmare to modify etc later on. Secondly, could you explain what you're trying to do a little bit better? Quote Link to comment Share on other sites More sharing options...
jpratt Posted June 12, 2009 Share Posted June 12, 2009 Thats cause you have two buttons created to submit the form. What is the other buttons purpose? Quote Link to comment Share on other sites More sharing options...
Darkmatter5 Posted June 12, 2009 Author Share Posted June 12, 2009 I need a button that when pressed activates and runs the following code in the <input> form elements above in the same form. The code for those is as follows <input type="text" name="abil_cha" size="2" value="<?php if(isset($_POST['reroll'])) { $werbgame->roll_dice(4,6,0,1); } ?>"> <?php echo substr($werb->getdata("descr","SELECT descr FROM d_abilities WHERE ability='charisma'"),0,50); ?> When the reroll button is pressed I'm wanting that PHP code to execute and generate the numbers. The second button is the submit button that actually submits the data from the form to a script file. As the code is right now it'll roll the numbers every time I press the reroll button. If I put the code "<form method="post" action="pcb.php">" in the form tag it breaks the roll generation and submits the data to the the file as the action prescribes. How can I get the submit button to submit the data and the reroll button to only make the the input form elements to regenerate new values? Thanks! Quote Link to comment Share on other sites More sharing options...
jpratt Posted June 12, 2009 Share Posted June 12, 2009 if you want to run the code without a page refresh you will probably have to use javascript to update the elements. Or are you fin with a refresh of the page? 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.