0

I have a form which works fine without it but when I add

CreditCardField::create('CreditCard','Credit Card')->setAttribute('placeholder', '0000')

it displays the credit card field with the same name, id and other attributes. When I go to submit it of course the validation throws an error as it's expecting an array but only gets a string of the last 4 digits.

Am I creating this field correctly? I'm assuming that once I fix the display issues it will fix the validation issues.

Rudiger
  • 6,749
  • 13
  • 51
  • 102

2 Answers2

1

I'm not hugely familiar with this field type, but you can see from it's template that it doesn't expect to be able to set a placeholder:

<span id="{$Name}_Holder" class="creditCardField">
    <input $AttributesHTML('id', 'name', 'value', 'tabindex') name="{$Name}[0]" value="{$ValueOne}" $TabIndexHTML(0)/>
    -
    <input $AttributesHTML('id', 'name', 'value', 'tabindex') name="{$Name}[1]" value="{$ValueTwo}" $TabIndexHTML(1)/>
    -
    <input $AttributesHTML('id', 'name', 'value', 'tabindex') name="{$Name}[2]" value="{$ValueThree}" $TabIndexHTML(2)/>
    -
    <input $AttributesHTML('id', 'name', 'value', 'tabindex') name="{$Name}[3]" value="{$ValueFour}" $TabIndexHTML(3)/>
</span>

The attributes you can set are ID, name, value and tabindex. Placeholder may be omitted deliberately for some sort of security reason, or it may just be a missing feature.

Your best bet might be to use some javascript instead:

$('#MyCreditCard_Holder').find('input').attr('placeholder', '0000');
Community
  • 1
  • 1
scrowler
  • 24,273
  • 9
  • 60
  • 92
  • It's the `$AttributesHTML('id', 'name', 'value', 'tabindex')` that is causing issues. Those attributes are meant to exclude them from the output however I can see in the raw source that it isn't and the second name one is. First one overrides the second which causes my issue. I've raised an issue on the framework. – Rudiger Jan 13 '17 at 04:18
1

So there is a bug in the template that I've logged a ticket for. The work around for it at the moment is you have to have your own CreditCardForm.ss template that uses $getAttributesHTML rather than $AttributesHTML

Rudiger
  • 6,749
  • 13
  • 51
  • 102