CodeIgniter Forums
Set value doesn,t return the value CI 2.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Set value doesn,t return the value CI 2.0 (/showthread.php?tid=39955)



Set value doesn,t return the value CI 2.0 - El Forum - 03-25-2011

[eluser]JuanitoDelCielo[/eluser]
I have one form to search

Code:
<?php echo form_open($search); ?>
<fieldset>
&lt;?php echo form_label('q', 'Buscar', array('class' => 'a-hidden')); ?&gt;
&lt;?php
$input = array(
'class' => 'text fl',
'name'  => 'q',
'value' => set_value('q', 'Search')
);
echo form_input($input);
?&gt;
</fieldset>

And it works, and using the profiler I know the value

POST DATA
$_POST['q'] Search String

So the input field should have the search String but it always show Search

Any ideas?


Set value doesn,t return the value CI 2.0 - El Forum - 03-25-2011

[eluser]InsiteFX[/eluser]
Thats because you have to post to controller/method!
Code:
echo form_open('email/send');

InsiteFX


Set value doesn,t return the value CI 2.0 - El Forum - 03-25-2011

[eluser]JuanitoDelCielo[/eluser]
This is the value of $search

Code:
$data->search = 'classified/index';



Set value doesn,t return the value CI 2.0 - El Forum - 03-25-2011

[eluser]bEz[/eluser]
Are you sending $data as an object instead of as an array?

Code:
$data['search'] = 'classified/index';



Set value doesn,t return the value CI 2.0 - El Forum - 03-25-2011

[eluser]JuanitoDelCielo[/eluser]
Yes but its the same. If you read the Loader.php code you will find this:

Code:
function view($view, $vars = array(), $return = FALSE)
{
    return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
}

...

function _ci_object_to_array($object)
{
    return (is_object($object)) ? get_object_vars($object) : $object;
}

get_object_vars


Set value doesn,t return the value CI 2.0 - El Forum - 03-28-2011

[eluser]JuanitoDelCielo[/eluser]
It was really easy. Just add a simple rule to via the form validataion class.