0

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.

  • do the forms have to be physically inside of the drop down menu? Or do you mean that you have a drop down menu, and based on the selection within that menu, either form A or form B will be shown? – Will Newton Apr 04 '14 at 17:29
  • The form takes you to a Moneris hosted pay page. I need to calculate the transaction before I send it to them. The drop down menu is not necessarily important I guess.. I just need some way of allowing the customer to choose BOTH form submit options rather than each one individually and separately. – user3345461 Apr 04 '14 at 17:32
  • oh i see. after looking at [this SO question](http://stackoverflow.com/questions/3008035/stop-an-input-field-in-a-form-from-being-submitted) it seems like you could make some JavaScript/JQuery that chooses which inputs get submitted. You can make 1 form and exclude inputs from it by removing their "name" value. Or you could just make 2 forms and have some redundancy. – Will Newton Apr 04 '14 at 17:39

3 Answers3

1

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.

bingo
  • 2,298
  • 1
  • 15
  • 21
0

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/

JajaDrinker
  • 652
  • 6
  • 15
0
   <?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>
Carlos
  • 357
  • 4
  • 21
  • This is very close but it still only takes the ONE CHARGE TOTAL when you send it to the Moneris page. I'm wondering if this will require Javascript? Or is it something with naming the values/names of the separate labels? – user3345461 Apr 04 '14 at 20:46
  • The way I posted, no javascript is required. The field is created with the same name, adding "[]" to the end of the name out, what makes it an array. Thus simply accesses them in php adding an index. option[0], option[1] ... How many you have. – Carlos Apr 06 '14 at 14:49