CodeIgniter Forums
how to set default value in form input -only for Add- - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: how to set default value in form input -only for Add- (/showthread.php?tid=82982)



how to set default value in form input -only for Add- - Ahmed Haroon - 09-06-2022

how i can add a default value in input form field which user trying Add data. if field is empty this should fill with default value otherwise show the saved value. currently i need it for a dropdown list. for some reasone, have 3 forms on a single table which are specific for their uses.
like a customer specific form to add a Customer it should contain user_type = "customer" 
if want to add a Rider it should contain user_type = "rider" 
same requirement in case where i want to restrict on other types of fields like a text, number, date, checkbox etc. 
please, if possible, have link(s) for different types of solution(s).
regards


RE: how to set default value in form input -only for Add- - InsiteFX - 09-07-2022

Please read:

PHP NET - Ternary Operator - Example #3 Assigning a default value


RE: how to set default value in form input -only for Add- - kenjis - 09-07-2022

See https://codeigniter.com/user_guide/helpers/form_helper.html#set_value