Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:59+00:00 2026-06-14T22:26:59+00:00

When I create a Drupal form with the API and construct the form as

  • 0

When I create a Drupal form with the API and construct the form as necessary, Braintree returns an authentication exception. When I take that same rendered HTML and output it on the page (skip the api), then it works. I can’t figure out why!

Below is the code that does not work.

function my_module_menu() {
  $items['user/payment/add'] = array(
    'title' => t('Add Card'),
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_module_add_form'),
    'access arguments' => array('access content'),
    'weight' => 2,
  );
}

function my_module_add_form() {

  global $user;

  require_once 'sites/all/libraries/braintree/lib/Braintree.php';

  Braintree_Configuration::environment('sandbox');
  Braintree_Configuration::merchantId('xxx');
  Braintree_Configuration::publicKey('xxx');
  Braintree_Configuration::privateKey('xxx');

  $customer = Braintree_Customer::find($user->uid);

  $trData = Braintree_TransparentRedirect::updateCustomerData(
    array(
      'redirectUrl' => 'http://www.xxx.com/user/payment',
      'customerId' => $user->uid
    )
  );

  $form['#action'] = url(Braintree_TransparentRedirect::url(), array('external' => true));
  $form['customer[first_name]'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name'),
  );
  $form['customer[last_name]'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name'),
);
  $form['tr_data'] = array(
    '#type' => 'hidden',
    '#value' => htmlentities($trData),
  );
  $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Save')
  );

  return $form;
}

if instead I take that exact HTML output and do this with a normal_menu_item and the same credentials as above…

function my_module_menu() {
  $items['user/payment/add'] = array(
    'title' => t('Add Card'),
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'my_module_add_page',
    'access arguments' => array('access content'),
    'weight' => 2,
  );
}


function my_module_add_page() {

  global $user;

  require_once 'sites/all/libraries/braintree/lib/Braintree.php';

  Braintree_Configuration::environment('sandbox');
  Braintree_Configuration::merchantId('xxx');
  Braintree_Configuration::publicKey('xxx');
  Braintree_Configuration::privateKey('xxx');

  $customer = Braintree_Customer::find($user->uid);

  $trData = Braintree_TransparentRedirect::updateCustomerData(
    array(
      'redirectUrl' => 'http://www.xxx.com/user/payment',
      'customerId' => $user->uid
    )
  );

    $output="

    <form accept-charset='UTF-8' id='tqcustom-billing' method='post' action='".Braintree_TransparentRedirect::url()."'>
    <div>
      <div class='form-item form-type-textfield form-item-customer-first-name'>
        <label for='edit-customer-first-name'>First Name </label>
        <input type='text' class='form-text' maxlength='128' size='60' value='' name='customer[first_name]' id='edit-customer-first-name'>
      </div>
      <div class='form-item form-type-textfield form-item-customer-last-name'>
        <label for='edit-customer-last-name'>Last Name </label>
        <input type='text' class='form-text' maxlength='128' size='60' value='' name='customer[last_name]' id='edit-customer-last-name'>
      </div>
      <input type='hidden' value='".$trData."' name='tr_data'>
      <input type='submit' class='form-submit' value='Save' name='op' id='edit-submit'>
    </div>
  </form>
  ";
  return $output;
}

it returns fine with a status code of 200. something about drupal_get_form or drupal_render kills the environment that braintree needs to authenticate the form post. What in the world could be causing this? The browser HTML output is 100% exactly the same both ways, but the first way won’t authenticate.

Please ask me for details and I’ll supply them – desperate to figure this out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:27:01+00:00Added an answer on June 14, 2026 at 10:27 pm

    In your first example you are passing the output of Braintree_TransparentRedirect::updateCustomerData through htmlentities before displaying the form. This will cause ampersands to appear as &amp; instead of &. Since the tr_data field is signed with your API key, it must be exactly what is returned from Braintree_TransparentRedirect::updateCustomerData.

    Disclaimer: I work for Braintree

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a data entry form in Drupal 7 that is
I am trying to create a form in drupal 6 that has multiple items
I’m using drupal to create some custom form that submit to a third party,
I am trying to create a filtering form for a Drupal module that show
I can create form with drupal forms api, but I don't know how to
I want to create a form in drupal 6 that user has force to
I want to create a registration form for dealers in my drupal website.Can any
I am looking for a module that can create sitemap in Drupal, but couldn't
I'm trying to resize an image that is uploaded to Drupal via a form.
I am trying to create a select list in drupal that is populated from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.