Welcome Guest, Not a member yet? Register   Sign In
Form Helper - set_value()
#7

(08-30-2015, 09:49 AM)RobertSF Wrote: So sorry to have led you astray! Sad The solution I posted works under CI 2.x, and I guess version 3 changed the code in the set_value function. Here's the code for version 2.


PHP Code:
/**
 * 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 '')
 {
 if (
FALSE === ($OBJ =& _get_validation_object()))
 {
 if ( ! isset(
$_POST[$field]))
 {
 return 
$default;
 }

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

 return 
form_prep($OBJ->set_value($field$default), $field);
 }

As you can see, here the function has two possible returns, one that uses $_POST and one that uses CI's internal storage.

Don't know how you feel about resorting to Javascript for this, but this function helps me when I want to prevent someone from returning to a previously filled and submitted form. They can return to it, but the form will be blank. It's extremely simple.

Code:
function formReset() {
this.form.reset()
}

When you say "Here is the code for version 2", do you mean CI v2, or version 2 of your set_value? lol.

And I love JS, but not sure id like to use JS for this one.

My bandaid ..
PHP Code:
<?php @$empty_values || print(set_value('menu_title', @$settings->menu_title)); ?>

.. works ok for now.
On the top of CI form related stuff though... You can look at this other issue! lol
Reply


Messages In This Thread
Form Helper - set_value() - by jLinux - 08-29-2015, 12:02 PM
RE: Form Helper - set_value() - by RobertSF - 08-29-2015, 04:03 PM
RE: Form Helper - set_value() - by jLinux - 08-29-2015, 07:10 PM
RE: Form Helper - set_value() - by jLinux - 08-30-2015, 09:16 AM
RE: Form Helper - set_value() - by jLinux - 08-30-2015, 09:36 AM
RE: Form Helper - set_value() - by RobertSF - 08-30-2015, 09:49 AM
RE: Form Helper - set_value() - by jLinux - 08-30-2015, 10:15 AM
RE: Form Helper - set_value() - by RobertSF - 08-30-2015, 10:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB