2
votes

I have a mobile website form that I want to add type attributes to the inputs so that there correct keyboard format will pop up.

However in cakephp setting the type as number a textarea is created instead of the input and the type is not set.

Setting type as text does work.

How do I overide this and have cakephp just keep it as a text input with type=number?

<?php echo $form->input('phone',array('type' => 'number')); ?>

Result:

  <textarea id="UserCardExpires" rows="6" cols="30" name="data[User][card_expires]"class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset"></textarea>

This is ok:

  <?php echo $form->input('postcode' ,array('type' => 'text')); ?> 

Result

  <input type="text" id="UserPostcode" name="data[User][postcode]" class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset">
2
What are the datatypes of the "phone" and "postcode" columns in your database? - Farray
They are varchar, users may include other characters in the form, so I am not strict on numbers. I jusr want the type set to number to bring up the num pad on the iphone - Keith Power
What happens if you do $form->text( 'phone', array( 'type' => 'number' ) );? What version of CakePHP are you on? - Farray
Thank you very much that did it. I am using 1.3. I know that 2.0 has support for html5. If you want to post that as an answer and I will mark it as the solution. - Keith Power

2 Answers

4
votes

On older versions of Cake, the Form helper won't automagically interpret $options['type'] as the HTML5 input-element type attribute. You have to force it by using "type" as an option on an explicit text element.

Use the following:

$form->text( 'phone', array( 'type' => 'number' ) );
1
votes

I think phone numbers might be:

echo $form->text( 'phone', array( 'type' => 'tel' ) );

EDIT:

Sorry I'm an idiot, thats HTML5.