Welcome Guest, Not a member yet? Register   Sign In
I don't understand the Form user guide
#1

[eluser]phantom-a[/eluser]
I'm looking in the User guide for making Forms

I don't understand how it means for the code to be used. Do you put the code in the controller or the View?

Here is Qoute for example.

Code:
form_dropdown()

$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );

$shirts_on_sale = array('small', 'large');

echo form_dropdown('shirts', $options, 'large');

// Would produce:

<select name="shirts">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>

umm where do I put that code?
#2

[eluser]tomcode[/eluser]
Both is possible.
#3

[eluser]textnotspeech[/eluser]
IMO, the form helper is for dynamically generated forms or specific use-case scenarios. In which case, you'd put it in the controller. Otherwise, I see no point to over-complicate something as simple as an HTML form. 95% of the time I simply put forms in the view the old fashioned way. There's no need to use php to generate something that can be done with static HTML. Just because there's a programmatic way to do something, doesn't mean you should. In general I try to avoid putting any php other than variables and arrays (foreach loops) in my views. A view shouldn't "process" information, it should display it.
#4

[eluser]plainas[/eluser]
This is exactly where things get a bit blurry. Like.. abstraction is the way and everything but no matter what one does, whatever kind of application we're talking about, there will ALWAYS be areas where abstraction layers overlay.

I follow a bit textnospeech's approach, but that's not always the best. Say you want to pass the view files to a designer, the less black boxes the best.
I guess the answer is: think ahead. Which part of the code is more likely be submitted to changes, how soon, how often...
#5

[eluser]metaltapimenye[/eluser]
[quote author="tomcode" date="1221544028"]Both is possible.[/quote]

yup, i agree..

why dont you try in your controller index?

Code:
...

function index(){
  $options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );
  echo form_dropdown('shirts', $options, 'large');
}
#tat's all .. and press F5 on your browser
...
#6

[eluser]tomcode[/eluser]
There's another thread going which discusses why using the CI helpers form/html instead plain HTML.

What's the benefit ...




Theme © iAndrew 2016 - Forum software by © MyBB