Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use form helpers over standard HTML?

Is it good for performance or security issue to use those class as we know that HTML should be in plain HTML.

Example:

in Codeigniter Framewỏrk:

 echo form_input(array('name' => 'one'));

is known as

<input type="text" name="one"/>

Which is better?

like image 436
Thanh Nguyen Avatar asked Feb 15 '13 04:02

Thanh Nguyen


1 Answers

Copied from Phil Sturgeon Blog:
The extra layer of abstraction, combined with helper extending/overriding makes it very easy to change simple bits of logic throughout your application output with minimal fuss.

To explain, I'll use an example.

<form action="<?php echo site_url('controller/method'); ?>" method="post">
vrs
<?php echo form_open('controller/method');

First you will see the standard HTML way to do it, with the site_url() function used to create the link to the form action. Second you will see the form_open() tag - and in this example its shorter too, wahey!

I wanted a way to set accept-charset="UTF-8" in all my forms to help keep my data all UTF-8 in CodeIgniter. If I was using just HTML then I would have to go through all my forms and add that in myself, which would be wasting time I could have spent at the pub.

Instead, as CodeIgniter allows you to extend helpers, I just made my own slightly modified form_open() in application/helpers/MY_form_helper.php which contained this logic.
Because I was using PHP to wrap my useful data, I could make one simple change and update all of my tags.

The main problem is people are looking at these HTML helper functions and seeing them purely as different syntax.

For complete article visit:
http://philsturgeon.co.uk/blog/2009/12/Why-CodeIgniter-HTML-helper-functions-rock

like image 133
Code Prank Avatar answered Sep 28 '22 15:09

Code Prank