2

I'd like to change the type of input field from text to numbers only.I've tried as following

<?= form_input('num', '','class="form-control" id="num", type="number"');?>

but not working

4 Answers 4

6

Try this one for numeric input:

$data = array(
  'name' => 'num',
  'id'   => 'num',
  'class'=> 'form-control',
  'type' => 'number'
);

echo form_input($data);
Sign up to request clarification or add additional context in comments.

Comments

5
$data = array(
  'name' => 'num',
  'id' => 'num',
  'class' => 'form-control',
  'type' => 'number'      //it's 'number', not 'numeric'
);

echo form_input($data);

Comments

1

You should pass everything as an associative array, here the array index are attribute of HTML input tag.

<?= form_input(array(
  'name' => 'num',
  'class' => 'form-control',
  'type' => 'number'// input type number
));
?>

more info: http://www.codeigniter.com/userguide2/helpers/form_helper.html

1 Comment

CodeIgniter doc's are now on the official codeigniter website codeigniter.com/docs
0

I find it useful to add a step parameter for currency fields.

echo form_input(array(
    'name' => 'estimated_cost',
    'id' => 'estimated_cost',
    'class' => 'form-control',
    'type' => 'number',
    'step' => 0.01
));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.