• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form Help

Just watched the tutorial on the codeigniter site about making the blog. When making the form for the comments, he doesn't use functions like form_input() or form_textarea(). Is this for a reason or were the functions recently added. Also, how would I go about making a text area with form_input field. I tried to use the user guide but I didn't really understand as it doesn't declare anywhere that it's a text area.

example from user guide:

$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',

echo form_input($data);

// Would produce:

<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" />

I don't understand why this would come out as a text input field?

The userguide tells us this - should work:
$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'rows'   => '8', // "rows" instead of "Maxlength" as with input type text
              'cols'        => '50', //"cols" instead of "size" as with input type text
              'style'       => 'width:50%'
echo form_textarea($data);

[eluser]Rok Biderman[/eluser]
If you're confused as for why should a thing like this actually exist - this is a helper, something to help you with making forms. It's basically a function that produces valid forms in a way that makes it easier to define it from a controller. You can easily choose not to use it, but it grows on you, not to mention it automates csrf_protection token, so you don't have to worry about it.

I think that the csrf_protection only works if you use form_open(), just using:

echo form_textarea($data); (or whatever input field/s you need for your form)

won't automatically implement csrf protection.

[eluser]Rok Biderman[/eluser]
By using form helper I meant everything, but of course, it's the form_open that actually does it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.