views:

101

answers:

3

Hello all,

I am new to codeigniter and I have just created a test login system. Chuffed...

I would like to make a form for this login system as I have just been passing the username/password directly for testing.

I am trying to work out the benefits of using the form helper. It helps me contsruct a form easily but can I not do this in just pure html? Is there another benefit of the form helper - I am just talking about the part that creates the form and not the validation - I am guessing I can use the validation regardless of how the form was created?

Thanks all

+2  A: 

The form helper exists to give you programmatic-control over your form. Yes, you could write it in HTML, but then you'll find yourself inserting PHP into your HTML when you want to auto-populate fields that need to persist between submissions and other similar stuff that is common to forms. Using this helper will keep your logic in the controller, and out of your views as much as possible.

By the way, good choice learning MVC!

Jonathan Sampson
I actually had trouble working out if I should put the form helper function calls in one of my views or the controller. I think its best in the view?Does it also mean I won't be able to make use of the form_validation rules?
Abs
I kept my `controller` thin, except for a fat `form_validation` that must run in `controller`. With this approach, I can write code faster, and debugging it easier. All business process is in `model`. All presentation code is in `view`. `Controller` is just to get the data from `model` and give it to `view`, or get the data from form, `validate` it, then give it to `model`. See my answers too.
Donny Kurnia
A: 

These are the functions from Form_Helper that I always use in view file of my projects:

  • form_open
  • form_close
  • form_dropdown
  • form_checkbox
  • form_radio
  • set_value

For other field type, such as <input type="text" />, I leave it as is, since the view file is a direct translation from a HTML file provided by a HTML/CSS designer in my team, or my client provide it. I kept the change minimal, and only use set_value in a value="" attribute of those form fields.

As it named helper, it is there to help you. It will make the complex function to select default value in select element easier. Your view file will be a lot cleaner, so it will be easier to read it and search for the bug source.

Form_validation have no connection with form_helper. Validation is run in controller, form_helper is in view. Validation is to filter the value before you process and put it in your database. Form_helper is to make your task to display form field and display or select default value easier. Bot can be used together, just one of it, or neither. It's all up to you.

Donny Kurnia
+1  A: 

check out this explanation of why you should use the form/html helpers. he makes some good points

http://philsturgeon.co.uk/news/2009/12/Why-CodeIgniter-HTML-helper-functions-rock

Tom Schlick