Welcome Guest, Not a member yet? Register   Sign In
set_value not working??
#1

[eluser]pendalpusher[/eluser]
I have a pretty extensive form going and I am using set_value() to repopulate if validation fails.

There are two fields on the page that will not repopulate ... can anyone tell me why?

Here is what I have in php
Code:
<?=form_label('Job Number','job_number');?>
<?=form_input('job_number',set_value('job_number'));?>

but no matter what i do it will not repopulate the form field all i get in the source code is this

Code:
//HTML OUTPUT
<label for="job_number">Job Number</label>
&lt;input type="text" name="job_number" value=""  /&gt;

anyone have an idea??

this happens on this field and one other one. I have checked and double checked the code, I even re-wrote the sections near the problems in case i missed something. But still nothing.

Thanks for any help.
P
#2

[eluser]GSV Sleeper Service[/eluser]
are you using the form validator?
#3

[eluser]pendalpusher[/eluser]
yes sorry

the form validation all seems to work. it yells at me when i am missing something and it moves me to the next step if i'm not.

the only things that are not working are these two form fields.
#4

[eluser]WanWizard[/eluser]
Are these two fields part of any form validation rule? Because that's required for set_value() to work...
#5

[eluser]GSV Sleeper Service[/eluser]
this is an issue with the set_value function. check the code for set_value.
set_value() basically says "is there a validation object? yes! great, grab the value from the validation object. No! ok, grab the value from the post array"
If the field you're trying to set the value of is not part of the validation rules then set_value will not work. you'll have to either add a dummy validation rule for your field, or make a change to set_value()
#6

[eluser]pendalpusher[/eluser]
ok .. that does make sense.

I did update the vaildation rules with dummy entries and that seems to work.

Thank you.

P
#7

[eluser]dizzyagain[/eluser]
Or you could follow Jermomes lead (in this bug report) and override the set_value function in your own form helper so that it will re-populate a field even if a validation rule doesn't exist for it.

Here is the code:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Form Value
*
* Grabs a value from the POST array for the specified field so you can
* re-populate an input field or textarea.  If Form Validation
* is active it retrieves the info from the validation class
*
* @access   public
* @param   string
* @return   mixed
*/
if ( ! function_exists('set_value'))
{
  function set_value($field = '', $default = '')
  {
      $OBJ =& _get_validation_object();

      if ($OBJ === TRUE && isset($OBJ->_field_data[$field]))
      {
        return form_prep($OBJ->set_value($field, $default));
      }
      else
      {
        if ( ! isset($_POST[$field]))
        {
          return $default;
        }

        return form_prep($_POST[$field]);
      }
  }
}

/* End of file MY_form_helper.php */
/* Location: ./application/helpers/MY_form_helper.php */
#8

[eluser]Unknown[/eluser]
The above code works GREAT, and saved me a ton of time coding rules that didn't need to be there! Thank you!
#9

[eluser]Unknown[/eluser]
[quote author="dizzyagain" date="1279582898"]Or you could follow Jermomes lead (in this bug report) and override the set_value function in your own form helper so that it will re-populate a field even if a validation rule doesn't exist for it.

Here is the code:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Form Value
*
* Grabs a value from the POST array for the specified field so you can
* re-populate an input field or textarea.  If Form Validation
* is active it retrieves the info from the validation class
*
* @access   public
* @param   string
* @return   mixed
*/
if ( ! function_exists('set_value'))
{
  function set_value($field = '', $default = '')
  {
      $OBJ =& _get_validation_object();

      if ($OBJ === TRUE && isset($OBJ->_field_data[$field]))
      {
        return form_prep($OBJ->set_value($field, $default));
      }
      else
      {
        if ( ! isset($_POST[$field]))
        {
          return $default;
        }

        return form_prep($_POST[$field]);
      }
  }
}

/* End of file MY_form_helper.php */
/* Location: ./application/helpers/MY_form_helper.php */
[/quote]

With this is one problem:

Code:
Example ' "
change into
Code:
Example  ' &quot;
next into
Code:
Example &amp;#39; &amp;quot;
and etc..

I deleted form_prep from last line with return but i am not sure is it good idea.
#10

[eluser]CroNiX[/eluser]
form_prep should be used as its own rule and not part of that one, so the developer has the control over the output.




Theme © iAndrew 2016 - Forum software by © MyBB