Welcome Guest, Not a member yet? Register   Sign In
set_value() in CI3 has issues with input arrays
#1
Exclamation 

In Codeigniter 2 our forms were able to have


PHP Code:
<input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" />
<
input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>" size="50" /> 
and each one would be populated from POST without an issue. With Codeigniter 3, all our forms that did that are now broken and I have to manually put in [0],[1],[2],etc for each form field's set_value(). Was this an intentional change or am I missing something that needed to be changed from CI2 to CI3?

The error
PHP Code:
A PHP Error was encountered
Severity
Notice
Message
: Array to string conversion 

I did look at the form_helper from CI2 and I saw it parsed out the values if it saw an array and returned them differently than they are being done in CI3.
Reply
#2

hi - hey i can confirm this does work for me in CI 3 so there must be something else going on. Are you using CI form validation? Are you sure you have 'field' => 'options[]' in the form validation? Are you sure you are loading form helper? If none of those things solve it then try naming the field something different then 'options' - maybe you have a conflict. And if that does not work then post more of your code and the specific error messages you are getting.
Reply
#3

(10-14-2016, 02:04 PM)cartalot Wrote: hi - hey i can confirm this does work for me in CI 3 so there must be something else going on. Are you using CI form validation? Are you sure you have 'field' => 'options[]' in the form validation? Are you sure you are loading form helper? If none of those things solve it then try naming the field something different then 'options' - maybe you have a conflict. And if that does not work then post more of your code and the specific error messages you are getting.


Not sure what you mean by 'field' => 'options[]'?

I use
PHP Code:
$this->form_validation->set_rules('options[]''Options''required'); 

I'm referencing https://www.codeigniter.com/userguide3/l...ield-names for this post by the way. Also, there is no other error messages, it's just that set_value() returns the whole array instead of the individual fields. Also, I'm using form_validation obviously and form_helper is loaded automatically(unless this changed in CI3) when you load that library.
Reply
#4

(This post was last modified: 10-16-2016, 10:52 AM by cartalot.)

i think you do need to load the form helper - or at least it shows doing that in the form validation example in the manual.
https://www.codeigniter.com/userguide3/l...controller
personally i would just autoload form helper and url helper in: application/config/autoload
then you don't have to worry about it.
Reply
#5

(10-16-2016, 10:50 AM)cartalot Wrote: i think you do need to load the form helper - or at least it shows doing that in the form validation example in the manual.
https://www.codeigniter.com/userguide3/l...controller
personally i would just autoload form helper and url helper in: application/config/autoload
then you don't have to worry about it.

Already I have done everything in previous as your instruction but till now not working.  
And Getting error till now . Sad

Attached Files Thumbnail(s)
   
Reply
#6

Check your PHP version and make sure your running PHP 5.6 or newer.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB