user3345461
user3345461

Reputation: 1

How to stack multiple forms (submit) in a dropdown menu?

I'm sorry if I'm not explaining this properly but I will do my best!

For example:

I have 2 forms, both with separate submit buttons.

    <FORM METHOD="POST" ACTION=https://www3.moneris.com/HPPDP/index.php>

    <INPUT TYPE="SUBMIT" NAME="SUBMIT" value="Session Fee - $200.00"  />

    <INPUT TYPE="HIDDEN" NAME="charge_total" value="200.00"  />

    <INPUT TYPE="HIDDEN" NAME="ps_store_id" VALUE="xxx" />

    <INPUT TYPE="HIDDEN" NAME="hpp_key" VALUE="xxx" />

    </FORM>


    <FORM METHOD="POST" ACTION=https://www3.moneris.com/HPPDP/index.php>

    <INPUT TYPE="submit" NAME="SUBMIT" value="Membership Fee - $15.00"  />

    <INPUT TYPE="HIDDEN" NAME="charge_total" value="15.00"  />

    <INPUT TYPE="HIDDEN" NAME="ps_store_id" VALUE="xxx" />

    <INPUT TYPE="HIDDEN" NAME="hpp_key" VALUE="xxx" />

    </FORM>

My question is.. How can I include both forms as either a drop down menu or a checkbox in which the customer can select either 1 or both of the options and click a final submit / pay now button.

So for example, they could select ONLY the Session Fee and the charge would come out as $200.00. Or should they choose, they can also select the Membership fee, and the charge would come out as $215.00.

Thank you in advance for your time - Much appreciated.

Upvotes: 0

Views: 206

Answers (3)

Carlos
Carlos

Reputation: 357

   <?php 
      if (isset($_POST['option'])) {

         foreach ($_POST['option'] as $key => $value) {
            echo $value.'<br>';
            echo $_POST['charge_total'][$key].'<br>';
            echo $_POST['ps_store_id'][$key].'<br>';
            echo $_POST['hpp_key'][$key];
            echo '<hr>';
         }

         echo '<br>';
      }
   ?>
   <form action="" method="POST">
      <label>
         <input type="checkbox" name="option[]" value="Session Fee">
         Session Fee - $200.00
         <input type="hidden" name="charge_total[]" value="200.00"  />
         <input type="hidden" name="ps_store_id[]" value="111" />
         <input type="hidden" name="hpp_key[]" value="222" />
      </label>
      <br>
      <label>
         <input type="checkbox" name="option[]" value="Membership Fee">
         Membership Fee - $15.00
         <input type="hidden" name="charge_total[]" value="200.00"  />
         <input type="hidden" name="ps_store_id[]" value="333" />
         <input type="hidden" name="hpp_key[]" value="444" />
      </label>
      <br>
      <input type="submit" value="Pay">
   </form>

Upvotes: 0

JajaDrinker
JajaDrinker

Reputation: 662

Here is a small code that shows you how to set up a select in a form.

you will need to adapt your server side code to get the selected value.

<FORM method="post" action="cgi-bin/script.pl">

    <SELECT name="fonction">
        <OPTION name="charge_total" VALUE="2000">charge Total 200$</OPTION>
        <OPTION name="Membership_Fee" VALUE="100">Member chip only 100$</OPTION>

    </SELECT>

    <INPUT type="submit" value="send">

</FORM>

Live exemple : http://jsfiddle.net/G4rur/

Upvotes: 0

bingo
bingo

Reputation: 2308

Put all of that stuff in one form. Swap out those submit buttons with check boxes and then create a new button to use to submit the form. On the server when the form is posted, refer to names of the checkboxes submitted, if they're checked look up the price for the fee and sum up a total from there.

Don't use those "charge_total" values posted from hidden fields to sum up your total charge, those can be manipulated on the front end prior to posting.

Upvotes: 1

Related Questions