EllisLab text mark
Advanced Search
2 of 2
2
   
why use form helpers over standard HTML?
Posted: 25 June 2010 02:08 PM   [ # 16 ]   [ Rating: 0 ]
Avatar
Joined: 2009-09-15
53 posts
pickupman - 25 June 2010 01:57 PM

Yeah now throw in that you want the input field already filled with a database entry. See how your form_input handles that

Oh, I think I can answer that:

//Controller
$data['field_name_value'= (isset($_POST['field_name'])) ? $this->input->post('field_name') : $result->field_name;

//View
echo form_input('field_name'set_value('field_name',htmlspecialchars($field_name_value))); 

Actually, this is all you have to do:

echo form_input('field_name'set_value('field_name'$result->field_name)); 

It uses the post value, if there is one. If not, it defaults to $result->field_name. Also, you don’t need to escape with htmlspecialchars. The helper does that for you.

 Signature 

CodeIgniter tutorials and more:

http://www.phpandstuff.com

CodeIgniter and Doctrine from scratch:

Day 1 - Day 2 - Day 3 - Day 4

 
Posted: 10 August 2010 11:00 AM   [ # 17 ]   [ Rating: 0 ]
Joined: 2007-08-13
26 posts

I use HTML directly, something like this:

<input type="text" name="name" value="<?=$user->name;?>" /> 

The $user variable is an object created at controller and passed to view, containing a string loaded from model/database when form state is “update record”, ~or~ an empty string when form state is “new record”.

 
Posted: 10 August 2010 01:02 PM   [ # 18 ]   [ Rating: 0 ]
Joined: 2010-04-07
14 posts
fMertins - 10 August 2010 03:00 PM

I use HTML directly, something like this:

<input type="text" name="name" value="<?=$user->name;?>" /> 

The $user variable is an object created at controller and passed to view, containing a string loaded from model/database when form state is “update record”, ~or~ an empty string when form state is “new record”.

Short tags are evil.

I prefer raw html to using the form helper.

 Signature 

:wq

 
Posted: 14 February 2013 04:45 PM   [ # 19 ]   [ Rating: 0 ]
Joined: 2013-02-14
1 posts
<input type="text" value="<?php print set_value('username', @$username); ?>" name="username" /> 

 

 
2 of 2
2