2

For PCI compliance reasons, I need to remove the name attribute from a form field.

I have tried:

(1)

$form['field']= array(
    '#name'=>'',
)

(2)

$form['field']= array(
    '#name'=>false,
)

3)

$form['field']= array(
    '#attributes' => array('name' => ''),
)

(4)

$form['field']= array(
    '#attributes' => array('name' => false),
)

None of the above work (each of the above produce a field with the name attribute present, just empty. I need it removed altogether).

I haven't managed to achive it with the hook_form_alter hook either.

Any ideas?

Thanks

2

Assuming it's a textfield, I think the simplest way would be via a preprocess on theme_textfield:

function MYMODULE_preprocess_textfield(&$vars) {
  // Identify the element and remove the name property (which will always be present)
  if ($vars['element']['#foo'] == 'bar') {
    unset($vars['element']['#name'];
  }
}

Bear in mind that Drupal won't be able to process the value for that field correctly if you submit the form, but I guess you're submitting this offsite anyway.

If it's not a textfield you should be able to use the same principle with the the theme function for whatever element type you're using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.