Welcome Guest, Not a member yet? Register   Sign In
Form Helper guidance
#1

[eluser]neversummer[/eluser]
I am having trouble getting the form helper to work and I cannot for the life of me figure out what I am doing wrong. I've read through the user guide and forums, but still no progress.

Originally I was trying to set the value of a dropdown using set_select, but could get that to work. So I thought I would try set_value on an input box as part of a troubleshooting exercise. I should add that I am autoloading the form helper, but also called it again in my controller function to make sure there wasn't something else going on.

In my view I have two input text controls:

Code:
<input type="text" name="zipcode" value="<?php echo set_value('zipcode'); ?>" />
<input type="text" name="zipcode2" value="<?php echo $row->zipcode; ?>" />

The set_value control does not populate a value (at all), while the second one does. What am I doing wrong here? Even more curious is the fact that I am using the form_open function to open this form and it's working without issue.

Thanks for your help.
#2

[eluser]TheFuzzy0ne[/eluser]
I'm not quite sure what's going on here. set_value() grabs the data from the $_POST array, but in the second line of your example, you appear to be using a database result to populate the field. Please could you be more specific about what it is you're trying to achieve? Perhaps showing the code for your controller method might allow us to understand better.
#3

[eluser]neversummer[/eluser]
Really all I am trying to do is understand how to use the form helper. Ultimately I want to be able to set the value of a drop down using set_select, but was doing some troubleshooting and found that I could not even get set_value to work. the reason you see two input controls was to verify that I can pass data to a control, but am not able to with set_value. Here is the controller function:

Code:
function view () {
        $this->load->helper('form');
        $header['title'] ='User Account Information';
        $data['heading'] ='User Account Information';
        $data['u_query'] = $this->Acct_model->get_user_detail_by_userid($this->userid);
        $header['logout'] = $this->logout;
        $this->load->view('header', $header);
        $this->load->view('account/user_profile_view', $data);
        $this->load->view('footer');
    }

As far as I can tell from the user guide and from forum posts the set_value code I posted in my previous post should work, but it does not. I'm just trying to figure out how to use that in hopes of shedding some light on how to properly use the set_select function.

Thanks for taking a look fuzzyone.
#4

[eluser]TheFuzzy0ne[/eluser]
Do you understand that set_value() only populates the the field data once the form has been submitted? Otherwise, the default is used (if specified), or '' is assumed to be the default value.
#5

[eluser]neversummer[/eluser]
No. I don't have a complete understanding of that and unfortunately, I'd say the user guide isn't very clear about that. Anyhow, I was attempting to set the value of a the input control from data stored in my database. It sounds like set_value is not intended for that use - is that correct?

Assuming that the form helper is only for submitted data, then what is the best method for setting the value of a select control from a value stored in the db? I incorrectly assumed it was set_select.

Hmmm, I guess I don't see the value of the set (value, select, checkbox, readio) functions.

thanks again for your guidance. It's much appreciated.

mike
#6

[eluser]TheFuzzy0ne[/eluser]
Yes, set_value() can be used for that:

Code:
<input type="text" name="zipcode" value="<?php echo set_value('zip_code', $row->zip_code); ?>" />

When the form is loaded for the first time, the default value you passed as the second parameter for set_value(), will be used to populate the text input. When the form is submitted, if your validation fails for whatever reason, the form can be redisplayed, only this time they are populated with the data from the $_POST array.

I hope this helps.
#7

[eluser]neversummer[/eluser]
OK, that definitely helps. Now, how does that concept translate to the set_select function if I am populating the form from the database?

the user guide suggests this:
Code:
<option value="CO" &lt;?php echo set_select('state', 'CO'); ?&gt; >Colorado </option>
<option value="CT" &lt;?php echo set_select('state', 'CT'); ?&gt; >Connecticut </option>
<option value="DE" &lt;?php echo set_select('state', 'DE'); ?&gt; >Delaware </option>
I've tried this and it doesn't populate the value.

Should I be doing something like this:
Code:
<option value="AL" &lt;?php echo set_select('state', $row->state); ?&gt; >Alabama </option>
<option value="AK" &lt;?php echo set_select('state', $row->state); ?&gt; >Alaska </option>
#8

[eluser]TheFuzzy0ne[/eluser]
Both bits of code you've posted should work. However, you may with to pass TRUE as the third parameter for to set one of those options as the default.

select_select() works just fine, however, I can't see a problem with your code as I can't see the contents of $row, but if there's a problem anywhere, then I'm guessing that where it is.




Theme © iAndrew 2016 - Forum software by © MyBB