문제

I am using CakePHP 2.2.4.

I am using the Form Helper to create a form. I need to have a form input with no name attribute.

Is this possible with the formhelper or should I just use HTML for creating this form?

eg in HTML:

<input type="text" maxlength="20" autocomplete="off" class="card-number stripe-sensitive required" />

Basically Am I able to do the above using the formhelper in CakePHP ?

Thanks.

도움이 되었습니까?

해결책

You can overrule any property in the $options array, which is the second argument to the input() method. So technically you could do:

echo $this->Form->input('Model.field', array(
    'label' => false,
    'div' => false,
    'name' => false,
    'maxlength' => 20,
    'autocomplete' => 'off',
    'class' => 'card-number stripe-sensitive'
));

But please be aware the dropping the name attribute makes the entire field useless if you want to do anything with it's data in your controller/model, as the $this->data array gets it's names from the name attribute of your input fields.

다른 팁

CakePHP needs the name attribute to be able to know what is being submitted by the form. I'm not sure I follow why you would want there to be no name attribute.

If you are concerned that a named input will be passing something to a save method you could always use unset in your controller to remove it from $this->request->data before saving/validation.

Otherwise, you can manually add the markup to your view, but again not sure why you would want an unnamed input element.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top