Welcome Guest, Not a member yet? Register   Sign In
form helper's set_value
#1

(This post was last modified: 07-06-2017, 06:38 PM by donpwinston.)

It would be nice if the set_value function's second parameter could be null. I have to explicitly change it to an empty string whenever it's null. I had to make my own set_value helper function.
Simpler is always better
Reply
#2

(This post was last modified: 07-07-2017, 03:15 PM by PaulD.)

Not sure what you mean.

If you do

PHP Code:
<input type="text" name="title" value="<?php echo set_value('something', ''); ?>" 

Then the field is blank if not previously submitted, or previously submitted value if submitted but with errors.

Or you can set it to a default value:

PHP Code:
<input type="text" name="title" value="<?php echo set_value('something', $title); ?>"

And you can set $title to an existing title (if editing) or blank or null if you have no existing value.

I am not sure that writing  ,'' in the set_value function is worth rewriting the set value function for.

I have just noticed in the docs that it gives this example:

Code:
<h5>Username</h5>
<?php echo form_error('username'); ?>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />

Which seems to imply that it defaults to NULL or blank anyway. I have not tested this, but if it does that anyway (which I was unaware of but makes sense) then I really do not understand what you are asking - sorry.

Paul

Oops. I just noticed this is about CI4, something about which I know very little. Sorry. I was talking about CI3, too much wine - sorry again. It is Friday night after all. Note to self: Stop posting when a bit skwiffy....
Reply




Theme © iAndrew 2016 - Forum software by © MyBB