Reply
Highlighted
Member
Posts: 2
Registered: ‎02-12-2014

DPM with PHP. How to add hidden fields?

I've read through the documentation plenty. It seems there is no easy way to add extra hidden fields to the getCreditCardForm string that is produced. The hidden fields are populated from the $sim form that is created inside the getCreditCardForm function. It seems the only way to add hidden fields would be to modify this function yourself. Is this really the case?  

Highlighted
Member
Posts: 2
Registered: ‎02-12-2014

Re: DPM with PHP. How to add hidden fields?

Well, I figured it out. It did require modification of the getCreditCardForm function, but wasn't that hard to do. I will document the steps I took here so others can folow.

 

First , add the fields you want to the function parameters on getCreditCardForm, located in lib/AuthorizeNetDPM.php

 

Original function protoype:

 

public static function getCreditCardForm($amount, $fp_sequence, $relay_response_url, $api_login_id, $transaction_key, $test_mode = true)

 Modified function prototype:

public static function getCreditCardForm($amount, $fp_sequence, $relay_response_url, $api_login_id, $transaction_key, $test_mode = true, $prefill = true,$shipfirst,$shiplast,$shipaddress,$shipcity,$shipstate,$shipzip,$shipemail,$lineitem,$teamname)

 Next, add the fields to the AuthorizeNetSIM_Form array literal. 

Original:

     array(
            'x_amount'        => $amount,
            'x_fp_sequence'   => $fp_sequence,
            'x_fp_hash'       => $fp,
            'x_fp_timestamp'  => $time,
            'x_relay_response'=> "TRUE",
            'x_relay_url'     => $relay_response_url,
            'x_login'         => $api_login_id,
          )

 Modified:

  array(
            'x_amount'        => $amount,
            'x_fp_sequence'   => $fp_sequence,
            'x_fp_hash'       => $fp,
            'x_fp_timestamp'  => $time,
            'x_relay_response'=> "TRUE",
            'x_relay_url'     => $relay_response_url,
            'x_login'         => $api_login_id,
            'x_ship_to_first_name' => $shipfirst,
            'x_ship_to_last_name' => $shiplast,
            'x_ship_to_address' => $shipaddress,
            'x_ship_to_city' => $shipcity,
            'x_ship_to_state' => $shipstate,
            'x_ship_to_zip' => $shipzip,
            'x_email' => $shipemail,
            'x_line_item' => $lineitem,
            )

 Now, any other merchant defined fields, such as I have "$teamname" simply add manually to the form HTML string lower down int he function.

 

Such as this:

...

  <form method="post" action="'.$post_url.'">
                '.$hidden_fields.'
                <input type="hidden" name="teamname" value="' . $teamname . '">

...