Default value for empty fields |
[eluser]rayed[/eluser]
Hi, Is there a helper function that allows to set default value if the field is empty, something like: Code: <?= default($title, "No title") ?> So it will display $title if it is available, or display "No title", that way I don't have to worry about unset or empty variables. I am used to use Smarty default modifier that do basically the same thing, and it was very handle. Rayed
[eluser]xwero[/eluser]
i use a modified input->post for this Code: function post($index = '', $default= FALSE, $xss_clean = FALSE) // added $default Code: $this->input->post('fieldname','default')
[eluser]rayed[/eluser]
Thanks xwero for your reply, but I was looking for a helper function to use it in views with variables passed from the controller . Currently I am using a custom helper with this function: Code: function ifempty($var, $default='') { I thought I would find something in the core CodeIgniter to replace my helper function.
[eluser]xwero[/eluser]
You could use the validation library for this as an alternative; validation default values but it seems unlogical to me to set default values for fields with validation if you are not going to validate.
|
Welcome Guest, Not a member yet? Register Sign In |