Jump to content

Help with running code with a button


Darkmatter5

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/161939-help-with-running-code-with-a-button/
Share on other sites

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!

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.