Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cakephp form input with no name attribute

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.

like image 999
Softinio Avatar asked Dec 15 '22 15:12

Softinio


2 Answers

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.

like image 80
Oldskool Avatar answered Dec 18 '22 04:12

Oldskool


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.

like image 40
drmonkeyninja Avatar answered Dec 18 '22 03:12

drmonkeyninja