• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form helper's set_value

#1
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.