Welcome Guest, Not a member yet? Register   Sign In
Function set_value() not working as expected
#1

[eluser]beachbum[/eluser]
I have the following html/php & codeigniter in my view for my contact form:

Code:
<input type='text' name='phone' id='phone' value="<?php echo set_value('phone'); ?>" />

I have used the set_value() function in all of the other fields in this form, and it works like a charm. However, it never works for this field, and I can't understand why it doesn't.

Incidentally, the "phone" field is the only field in the form (besides the submit button) for which I have not used any validation with the form_validation library. That is the only anamoly that I've been able to find, but the fact that I didn't set a validation rule for this field should not prevent the set_value() function from working, should it?

Thanks!

Contact form
#2

[eluser]beachbum[/eluser]
On a sneaking suspicion that the problem mentioned in my previous post may be somehow tied to the validation rules (or lack thereof) for the "phone" field, I set a validation rule that ensures the value entered in the "phone" field is numeric.

Now, set_value() works for that field. Why does it not work if the field has no validation rule applied to it?
#3

[eluser]orotone[/eluser]
I'm having this same problem and searched here before posting. With form validation on 1.7 if I don't have a rule then the set_value and set_radio form helpers do not work (I've not tried the set_checkbox and other helpers, but they probably don't work with validation either). I can set a rule on all the set_value fields if that's the work-around, but what rule can I use for a radio since I don't require it to be set? Any ideas about a better work-around, etc. would be much appreciated. I'm using 1.7 SVN.
#4

[eluser]orotone[/eluser]
Isn't anyone else having this problem? Have we missed something in the documentation? I guess I can go back to javascript validation on these old web-sites that I'm trying to update to CI.
Thanks,
OT
#5

[eluser]jstrebel[/eluser]
Same here.. seems you have to explicitly set a rule for <field> for the set_value(<field>); to do anything.

This would be a TON more helpful if set_value() would work with any field in the $_POST array
#6

[eluser]jstrebel[/eluser]
Also for the life of me I cannot get the validation to work for fields using arrays:

My view:
Code:
&lt;?=form_error('i[]'); ?&gt;
&lt;input type='text' name="i[]" size="30" value="&lt;?=set_value('i[]'); ?&gt;"/&gt;
&lt;input type='text' name="i[]" size="30" value="&lt;?=set_value('i[]'); ?&gt;"/&gt;
&lt;input type='text' name="i[]" size="30" value="&lt;?=set_value('i[]'); ?&gt;"/&gt;
My Controller rule:
Code:
$this->form_validation->set_rules('i[]', 'Name', 'required|min_length[5]');

On submission with empty fields, no error message is shown, and it repopulates the field with a string "Array"

The $_POST array looks like:
Code:
Array
(
    [title] =>
    [rtype] => 1
    [cite_source] =>
    [desc] =>
    [i] => Array
    [tags] =>
    [recipeForm] => Create
)
$_POST\[i\] is given a string value of "Array"

The rest of the validation on the form works fine, title, desc, etc.. those fields all show errors and get repopulated as needed.

Using latest CI code set: Updated external to revision 1580.

What gives?
#7

[eluser]orotone[/eluser]
It is reported as an "unconfirmed" bug in the bug tracker and I believe it only fails when you're using form validation. When you look at the code for set_value, you can see that it's checking for a validation object and getting from the POST array depending on that check. I've not had time to personally debug it yet and have gone back to using non-CI validation, etc. The slow response on this and lack of interest in the community makes me realize that I probably shouldn't use CI for anything mission critical at this time.
#8

[eluser]cwt137[/eluser]
Hello,

Attached is a patch against the SVN trunk that I hope corrects the issue with set_value() and the form field name being an array. The problem was that set_value() doesn't take into account that the form field might be an array like set_radio() and the other set methods inside the form_validation class. So, I copied the code from set_radio() and modified it. I also modified the form helper class too to do the same thing. But, the form_helper class doesn't seem to work unless you define a validation rule. That is probably a different bug or just me coding something wrong. I'll post a note for this patch in bug #6446
#9

[eluser]ifew[/eluser]
hello
patch from cwt137
i can't use this, it return first field value to every input
#10

[eluser]ifew[/eluser]
ok, this patch can use for

&lt;input type='text' name="optoin[0]" size="30" value="&lt;?=set_value('optoin[0]'); ?&gt;"/&gt;
&lt;input type='text' name="optoin[1]" size="30" value="&lt;?=set_value('optoin[1]'); ?&gt;"/&gt;
&lt;input type='text' name="optoin[2]" size="30" value="&lt;?=set_value('optoin[2]'); ?&gt;"/&gt;

and set in rule

array(
'field' => 'skill_input[0]',
'label' => 'lang:user_option',
'rules' => 'trim|htmlspecialchars|xss_clean'
),
array(
'field' => 'skill_input[1]',
'label' => 'lang:user_option',
'rules' => 'trim|htmlspecialchars|xss_clean'
),
array(
'field' => 'skill_input[2]',
'label' => 'lang:user_option',
'rules' => 'trim|htmlspecialchars|xss_clean'
)




Theme © iAndrew 2016 - Forum software by © MyBB