[eluser]dopple[/eluser]
Am I missing something or does this seem like an awful lot of code to output a form with 6 text fields and a submit button? Is there a cleaner way to do this?
Code: <?php
echo form_open('contact_user/add_contact_user');
$data = array(
'name' => 'username',
'id' => 'username',
'maxlength' => '100',
);
echo form_label('Username', 'username');
echo form_input($data) . "<br />\n";
$data = array(
'name' => 'forename',
'id' => 'forename',
'maxlength' => '100',
);
echo form_label('Forename', 'forename');
echo form_input($data) . "<br />\n";
$data = array(
'name' => 'surname',
'id' => 'surname',
'maxlength' => '100',
);
echo form_label('Surname', 'surname');
echo form_input($data) . "<br />\n";
$data = array(
'name' => 'email',
'id' => 'email',
'maxlength' => '100',
);
echo form_label('Email Address', 'email');
echo form_input($data) . "<br />\n";
$data = array(
'name' => 'password',
'id' => 'password',
'maxlength' => '100',
);
echo form_label('Password', 'password');
echo form_input($data) . "<br />\n";
$data = array(
'name' => 'section',
'id' => 'section',
'maxlength' => '100',
);
echo form_label('Section', 'section');
echo form_input($data) . "<br />\n";
echo form_submit('submit', 'Save');
echo form_close();
?>
[eluser]Dam1an[/eluser]
Why yes that is a lot of code for a form with 6 input fields, which is why I don't use the form helpers.
Why don't you just do it using normal HTML? (although I do still use set_value from the validation library in my forms)
[eluser]ggoforth[/eluser]
I agree. I don't use the form helpers either. Plain HTML seems to be the way to go here. Like the previous poster I do make good use of set_value().
[eluser]Dam1an[/eluser]
[quote author="ggoforth" date="1245979582"]Like the previous poster I do make good use of set_value().[/quote]
The 'previous poster' has a name
[eluser]ggoforth[/eluser]
[quote author="Dam1an" date="1245979829"]The 'previous poster' has a name  [/quote]
Sorry Damian, I was on my iPhone so I was zoomed in on the post content and couldn't see the avatar. My bad!
Greg
[eluser]slowgary[/eluser]
The previous poster is always on his stupid iPhone, GOSH! ;-P
I don't use the form helper either, or any of the HTML helpers as I think they're silly (although I can see the benefit of table or multidimensional unordered list generation). I also don't understand how one would go about creating a complex form with a nice layout using the helper, as I usually layout my forms with a table and sometimes there are just so many colspans/rowspans that it's confusing enough just doing it with HTML.
[eluser]Dam1an[/eluser]
I thought you where going to say the previous poster is always Damian lol
And Eugh! tables for forms?
[eluser]slowgary[/eluser]
I don't use tables for site layout, and I really think they should be reserved for data in a grid (which is what they were made for), but I just don't know a better way to layout forms. Are your forms div based or something else?
[eluser]Dam1an[/eluser]
Yeah, divs all the way 
I'll try dig out a few resources for you when I get to work (about to leave the house now)
[eluser]ggoforth[/eluser]
I am guilty of occasionally using tables to layout forms. I have started doing something like this though:
Code: <div>
<label for='somefield' style='width:10em;float:left;'>My Label</label><input type='text' id='somefield' name='somefield' />
<label for='somefield2' style='width:10em;float:left;'>My Label</label><input type='text' id='somefield2' name='somefield2' />
</div>
The code above keeps all the form elements laid out evenly and no tables had to be used. This is now my primary method for laying out forms. (Oh, I used inline styles here just to demonstrate the principal. That would usually be found in my css sheets.
Greg
|