<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Get PHP variables in validation</title>
		<link>https://legacy.forums.gravityhelp.com/topic/get-php-variables-in-validation</link>
		<description>Gravity Support Forums Topic: Get PHP variables in validation</description>
		<language>en-US</language>
		<pubDate>Wed, 22 Apr 2026 12:57:14 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/get-php-variables-in-validation" rel="self" type="application/rss+xml" />

		<item>
			<title>dn11233455 on "Get PHP variables in validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/get-php-variables-in-validation#post-63458</link>
			<pubDate>Sun, 24 Jun 2012 20:41:12 +0000</pubDate>
			<dc:creator>dn11233455</dc:creator>
			<guid isPermaLink="false">63458@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I am trying to integrate NGPVAN's contribution services with Gravity Forms. Their API takes a PHP array that looks something like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$d = new NgpDonation(&#38;#39;your-credentials&#38;#39;, true, array(
    &#38;#39;FirstName&#38;#39; =&#38;gt; &#38;#39;John&#38;#39;,
    &#38;#39;LastName&#38;#39; =&#38;gt; &#38;#39;Doe&#38;#39;,
    &#38;#39;Address1&#38;#39; =&#38;gt; &#38;#39;100 Elm Street&#38;#39;,
    &#38;#39;Zip&#38;#39; =&#38;gt; &#38;#39;12345&#38;#39;,
    &#38;#39;Cycle&#38;#39; =&#38;gt; &#38;#39;2012&#38;#39;,
    &#38;#39;Amount&#38;#39; =&#38;gt; &#38;#39;50.00&#38;#39;,
    &#38;#39;CreditCardNumber&#38;#39; =&#38;gt; &#38;#39;4111111111111111&#38;#39;,
    &#38;#39;ExpYear&#38;#39; =&#38;gt; &#38;#39;13&#38;#39;,
    &#38;#39;ExpMonth&#38;#39; =&#38;gt; &#38;#39;05&#38;#39;
));&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;with many other possible fields. My code for validation is:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_validation&#38;quot;, &#38;quot;process_credit_card_data&#38;quot;);

/*
* Courtsey of
* &#60;a href=&#34;http://www.newmediacampaigns.com/blog/accept-campaign-donations-with-the-ngp-contribution-api&#34; rel=&#34;nofollow&#34;&#62;http://www.newmediacampaigns.com/blog/accept-campaign-donations-with-the-ngp-contribution-api&#60;/a&#62;
* &#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_validation&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/documentation/page/Gform_validation&#60;/a&#62;
*/

function process_credit_card_data($validation_result) {
    // print_r($form); // for debugging
    // print_r($validation_result);
    // print_r($_POST);
    if ($validation_result[&#38;#39;is_valid&#38;#39;]) {
                    // cycle information
            $cycle = &#38;#39;2012&#38;#39;;
        /* ******************** General Web Contribute Form ******************** */
        if (($validation_result[&#38;#39;form&#38;#39;][&#38;#39;id&#38;#39;] == 4)) {
            $source = &#38;#39;ccOnline&#38;#39;;
      // attempt payment -- being ready to reject if needed.
            // name information
            $firstName = rgpost(&#38;quot;input_{$field[&#38;#39;16&#38;#39;]}&#38;quot;);
            $lastName = rgpost(&#38;quot;input_{$field[&#38;#39;17&#38;#39;]}&#38;quot;);
            $email = rgpost(&#38;quot;input_{$field[&#38;#39;3&#38;#39;]}&#38;quot;);
            $phone = rgpost(&#38;quot;input_{$field[&#38;#39;4&#38;#39;]}&#38;quot;);

            // address information
                $address1 = rgpost(&#38;quot;input_{$field[&#38;#39;18&#38;#39;]}&#38;quot;);
                $address2 = rgpost(&#38;quot;input_{$field[&#38;#39;19&#38;#39;]}&#38;quot;);
                $city = rgpost(&#38;quot;input_{$field[&#38;#39;20&#38;#39;]}&#38;quot;);
                $state = rgpost(&#38;quot;input_{$field[&#38;#39;21&#38;#39;]}&#38;quot;);
                $zip = rgpost(&#38;quot;input_{$field[&#38;#39;22&#38;#39;]}&#38;quot;);

            // amount information
              $amountradio = rgpost(&#38;quot;input_{$field[&#38;#39;6&#38;#39;]}&#38;quot;);
              $amount = &#38;#39;5&#38;#39;;

		    // credit card information
            $ccnum = rgpost(&#38;quot;input_{$field[&#38;#39;8&#38;#39;]}&#38;quot;);
            $exmonth = rgpost(&#38;quot;input_{$field[&#38;#39;9&#38;#39;]}&#38;quot;);
            $exyear = rgpost(&#38;quot;input_{$field[&#38;#39;10&#38;#39;]}&#38;quot;);

            // recurring information
         //   $recurring = rgpost(&#38;quot;input_11&#38;#39;);
          //  $recurringfreq = rgpost(&#38;quot;input_12&#38;#39;);
         //   $recurringtotal = rgpost(&#38;quot;input_13&#38;#39;);

            // employment information
            $employer = rgpost(&#38;quot;input_{$field[&#38;#39;14&#38;#39;]}&#38;quot;);
            $occupation = rgpost(&#38;quot;input_{$field[&#38;#39;15&#38;#39;]}&#38;quot;);

            $result = do_transaction($lastName, $firstName, $email, $phone, $address1, $address2, $city, $state, $zip, $amount, $ccnum, $expMonth, $expYear, $employer, $occupation, $cycle, $source);
            if ($result !== true) {
                $validation_result[&#38;#39;is_valid&#38;#39;] = false;
                foreach($validation_result[&#38;quot;form&#38;quot;][&#38;quot;fields&#38;quot;] as &#38;amp;$field){
                    if ($field[&#38;quot;id&#38;quot;] == &#38;quot;8&#38;quot;){
                        $field[&#38;quot;failed_validation&#38;quot;] = true;
                        $field[&#38;quot;validation_message&#38;quot;] = $result;
                        break;
                    }
                }
                } else {
                // I like to blank credit card data so it&#38;#39;s not stored locally.
                $_POST[&#38;#39;input_8&#38;#39;] = &#38;#39;*****&#38;#39;;
            }
            return $validation_result;
            /* ******************** End General Web Contribute Form ******************** */
            } else {
            return $validation_result;
        }
        } else {
        return $validation_result;
    }
}

 // This is the function that is called above
function do_transaction($lastName, $firstName, $email, $phone, $address1, $address2, $city, $state, $zip, $amount, $ccnum, $exmonth, $exyear, $employer, $occupation, $cycle, $source) {
    require &#38;#39;NgpDonation.php&#38;#39;;

    // Your string goes below. Will look something like the following:
    $apiString = &#38;quot;*******REDACTED FOR CONFIDENTIALITY********&#38;quot;;
    $d = new NgpDonation($apiString, true, array(
    &#38;#39;FirstName&#38;#39; =&#38;gt; $firstName,
    &#38;#39;LastName&#38;#39; =&#38;gt; $lastName,
    &#38;#39;Email&#38;#39; =&#38;gt; $email,
    &#38;#39;HomePhone&#38;#39; =&#38;gt; $phone,
    &#38;#39;Address1&#38;#39; =&#38;gt; $address1,
    &#38;#39;Address2&#38;#39; =&#38;gt; $address2,
    &#38;#39;City&#38;#39; =&#38;gt; $city,
    &#38;#39;State&#38;#39; =&#38;gt; $state,
    &#38;#39;Zip&#38;#39; =&#38;gt; $zip,
    &#38;#39;Cycle&#38;#39; =&#38;gt; $cycle,
    &#38;#39;Amount&#38;#39; =&#38;gt; $amount,
    &#38;#39;CreditCardNumber&#38;#39; =&#38;gt; $ccnum,
    &#38;#39;ExpYear&#38;#39; =&#38;gt; $exyear,
    &#38;#39;ExpMonth&#38;#39; =&#38;gt; $exmonth,
    &#38;#39;Employer&#38;#39; =&#38;gt; $employer,
    &#38;#39;Occupation&#38;#39; =&#38;gt; $occupation,
    &#38;#39;Source&#38;#39; =&#38;gt; $source
    ));
    $result = $d-&#38;gt;save();
    if ($result) {
        return true;
        } else {
        if ( $d-&#38;gt;hasErrors() ) {
            $errors = $d-&#38;gt;getErrors();
            //print_r($errors);
        }
        if ( $d-&#38;gt;hasFault() ) {
            $fault = $d-&#38;gt;getFault();
            //print_r($fault);
        }
        $result = $d-&#38;gt;getResult();
        $errorString = &#38;#39;testingerror&#38;#39;;
        return $errorString;
    }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Every time I send the form I get the validation error. Am I pulling the variables incorrectly? Any help would be greatly appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
