CodeIgniter Forums
form helper's set_value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: form helper's set_value (/showthread.php?tid=68409)



form helper's set_value - donpwinston - 07-06-2017

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.


RE: form helper's set_value - PaulD - 07-07-2017

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