CodeIgniter Forums

Full Version: form helper's set_value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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:

<?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.


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....