-
-
Save wizonesolutions/2657961 to your computer and use it in GitHub Desktop.
Test Drupal FAPI does not receive date when name attribute is removed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function stripe_test_menu() { | |
$items = array(); | |
$items['stripe-test'] = array( | |
'title' => t('Stripe Test'), | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('stripe_test_form'), | |
'access callback' => TRUE, | |
); | |
return $items; | |
} | |
function stripe_test_form($form, &$form_state) { | |
$js = <<<EJS | |
jQuery(function() { | |
jQuery('#edit-remove-names').click(function() { | |
var check = jQuery(this); | |
check.attr('disabled', 'disabled'); | |
jQuery(':text').removeAttr('name'); | |
}) | |
}) | |
EJS; | |
drupal_add_js($js, 'inline'); | |
$form['card-number'] = array( | |
'#type' => 'textfield', | |
'#title' => t('Credit Card Number'), | |
); | |
$form['card-exp'] = array( | |
'#type' => 'fieldset', | |
'#title' => t('Card Expiration'), | |
); | |
$form['card-exp']['month'] = array( | |
'#type' => 'textfield', | |
'#title' => t('Month'), | |
); | |
$form['card-exp']['year'] = array( | |
'#type' => 'textfield', | |
'#title' => t('Year'), | |
); | |
$form['remove-names'] = array( | |
'#type' => 'checkbox', | |
'#title' => 'Remove name attributes', | |
); | |
$form['submit'] = array( | |
'#type' => 'submit', | |
'#value' => t('Save'), | |
); | |
return $form; | |
} | |
function stripe_test_form_submit($form, &$form_state) { | |
drupal_set_message(print_r($form_state['values'], true)); | |
} |
What about something like:
<?php
function uc_payment_method_stripe_form($form, &$form_state, $order) {
$form['card-number'] = array(
'#type' => 'textfield',
'#size' => 20,
'#attributes' => array(
'data-stripe' => 'number',
),
);
$form['card-number']['#pre_render'][] = 'stripe_pre_render_sensitive_textfield';
}
function stripe_pre_render_sensitive_textfield($elements) {
unset($elements['#name']);
return $elements;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hmm, this solution looks like it would have PCI-DSS issues if the user had JavaScript disabled.