-1

I have 3 name fields in a codeigniter view. When I type in the name in these 3 fields, I want the first letter of the name to be capital letter.

How do I do this?

  <?=form_input(['name'=>'last_name','class'=>'form-control','placeholder'=>'Enter your last name','value'=>set_value('last_name')])?>

I need first letter of my name in capital letters. This needs to be inserted in to database table field with the same.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
karthick
  • 21
  • 4
  • try to use `ucwords()` before adding in `database` – M.Hemant May 21 '19 at 07:49
  • where do I use ucwords() ? – karthick May 21 '19 at 07:49
  • before inserting in db in model – M.Hemant May 21 '19 at 07:51
  • but i need the first letter of name to come in capital letters in my view as well – karthick May 21 '19 at 07:53
  • there is a reason why this isn't done. what if the users last name is `von Buren`? see also: https://stackoverflow.com/questions/10580554/proper-capitalization-of-surnames-in-php – Alex May 21 '19 at 08:16
  • I have some text boxes in my view like this: =form_input(['name'=>'last_name','type'=>'text','style'=>'text-transform:capitalize','class'=>'form-control','placeholder'=>'Enter your last name','value'=>set_value('last_name')])?> i have a database table 'userlogin' which has a field 'last_name' when I am entering the value in the last_name field, i want autofill function in it with all the values from 'last_name' field in database. How do i do this? – karthick May 21 '19 at 09:36

1 Answers1

1

To show in view Please Use CSS text-transform to do this

<input type='text' name='f_name' style='text-transform:capitalize'>
<br>
<input type='text' name='l_name'>

You can see here f_name will start with a capital letter and l_name will not

After submitting your form you must need to use ucword() in controller or Model before inserting in DB

Controller:

$fname = ucword($this->input->post('f_name'));
$lname = ucword($this->input->post('l_name'));

then send it to Model to save it

M.Hemant
  • 2,345
  • 1
  • 9
  • 14
  • will this also post with the first letter capitalized? (not op, just curious) – Alex May 21 '19 at 08:15
  • No, it will not post, OP, need to use `ucwords()` in the controller as i mentioned in above comment – M.Hemant May 21 '19 at 08:15
  • i've just checked. if you have caps lock off, and you type `asd` even though it looks like `Asd` it will post as `asd`. This solution would have to be used in conjunction with ucwords. – Alex May 21 '19 at 08:20
  • code updated. Kindly accept the answer if it is worked – M.Hemant May 21 '19 at 08:26
  • please accept the answer, and ask your question as new question in SO – M.Hemant May 21 '19 at 10:00