![]() |
set_value() is working but set_select() not working - 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: set_value() is working but set_select() not working (/showthread.php?tid=88432) Pages:
1
2
|
set_value() is working but set_select() not working - sknair143 - 09-07-2023 Hello, I'm trying to use set_value() and set_select(), Everything is correct but set_select() is not working. Form : Code: <select name="doc_type_id" class="form-select"> Model : Code: <?php Here set_value() function is working as expected. but set_select() is not working, the same i used in another form is working fine. RE: set_value() is working but set_select() not working - sammyskills - 09-07-2023 What exactly are you trying to achieve? And why not show your controller code also? RE: set_value() is working but set_select() not working - sknair143 - 09-07-2023 (09-07-2023, 08:11 AM)sammyskills Wrote: What exactly are you trying to achieve? Controller : Code: public function createDocument() What im trying to achieve is, I have a form to add employee's supporting documents like ID Card, Passport etc... So in the form I have one select box and other input boxes. I need to keep the old entered value to the field if validaiton fails. So for that i use set_select() for select box and set_value() for input boxes. set_value() is not working. RE: set_value() is working but set_select() not working - InsiteFX - 09-07-2023 Your problem is your passing an object array to the view from find not an associated array PHP Code: // so to access just use: RE: set_value() is working but set_select() not working - sknair143 - 09-07-2023 (09-07-2023, 10:26 PM)InsiteFX Wrote: Your problem is your passing an object array to the view from find not an associated array No. because the option values are getting printed. When i use your code it gives me error like : Code: Attempt to read property "id" on array RE: set_value() is working but set_select() not working - sammyskills - 09-07-2023 Can you confirm by adding the code below, somewhere in your code, and run the validation again? PHP Code: <?= set_value('doc_type_id') ?> Just to confirm that the value is returned to the form if validation fails. PS: I see that you are using Entity Classes in your controller (DocumentsEntity). Instead of adding the properties individually, you can use the fill() method to have the properties filled automatically for you, like so: PHP Code: $document = new DocumentsEntity(); See docs. RE: set_value() is working but set_select() not working - sknair143 - 09-08-2023 (09-07-2023, 11:56 PM)sammyskills Wrote: Can you confirm by adding the code below, somewhere in your code, and run the validation again? I checked. The value is returned is NULL If i use fill() method, how i can process the uploaded doc file ? RE: set_value() is working but set_select() not working - sammyskills - 09-08-2023 If the value is null, then that means that it is not being sent in the first place. Try adding this in your controller, before the checks, to see what your form sends: PHP Code: dd($this->request->getPost()); RE: set_value() is working but set_select() not working - sknair143 - 09-08-2023 (09-08-2023, 12:13 AM)sammyskills Wrote: If the value is null, then that means that it is not being sent in the first place. Try adding this in your controller, before the checks, to see what your form sends: Code: $this->request->getPost() array (3) It returns here. RE: set_value() is working but set_select() not working - sammyskills - 09-08-2023 (09-08-2023, 12:07 AM)sknair143 Wrote: If i use fill() method, how i can process the uploaded doc file ? Oh, I didn't notice that you used the getFile() method. Which brings me to wonder how you were or wanted to save the doc file in the database? |