CodeIgniter Forums
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


RE: set_value() is working but set_select() not working - sknair143 - 09-08-2023

(09-08-2023, 12:16 AM)sammyskills Wrote:
(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?

I want to move to the local folder and save the path into the doc_file field in database, that i can manage to do but im in trouble with set_select() function. I didnt understand what is making wrong, everything seems to be correct.


RE: set_value() is working but set_select() not working - sammyskills - 09-08-2023

Put this in your controller, and echo it in your view:

PHP Code:
$oldSelect $this->request->getOldInput('doc_type_id'); 



RE: set_value() is working but set_select() not working - sknair143 - 09-08-2023

(09-08-2023, 12:34 AM)sammyskills Wrote: Put this in your controller, and echo it in your view:

PHP Code:
$oldSelect $this->request->getOldInput('doc_type_id'); 

This also returning NULL

This also returning NUL

Code:
$oldSelect = $this->request->getOldInput('no');

I figure it out something, When i move the select box to second position it works but now the first inputbox (Doc no) not working.

Code:
<?php echo form_open_multipart('') ?>


        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Doc No</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="<?= set_value('no') ?>" name="no"
                    id="basic-default-company" placeholder="1995/23234/3434DF">
                <span class="error">
                    <?= session('errors.no'); ?>
                </span>
            </div>

        </div>
        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-name">Document Type</label>
            <div class="col-sm-10">
                <select name="doc_type_id" id="doc_type_id" class="form-select">
                    <option value="">Select</option>

                    <?php foreach ($doc_types as $doc): ?>
                        <option value="<?= $doc['id']; ?>" <?= set_select('doc_type_id', $doc['id']) ?>> <?= $doc['name']; ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <span class="error">
                    <?= session('errors.doc_type_id'); ?>
                </span>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Expiry Date</label>
            <div class="col-sm-10">
                <input class="form-control" type="date" value="<?= set_value('expiry_date') ?>" name="expiry_date"
                    value="" id="html5-date-input">
                <span class="error">
                    <?= session('errors.expiry_date'); ?>
                </span>
            </div>

        </div>

        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Upload Doc <br /><small>(Allowed JPG, GIF
                    or
                    PNG)</small></label>
            <div class="col-sm-10">
                <input class="form-control" type="file" name="doc_file" id="formFile">
                <span class="error">
                    <?= session('errors.doc_file') ?>

                </span>
            </div>


        </div>

        <div class="row justify-content-end">
            <div class="col-sm-10">
                <button type="submit" class="btn btn-primary">Save</button>
            </div>
        </div>
        </form>


I think the issue with SESSION


RE: set_value() is working but set_select() not working - sknair143 - 09-08-2023

Hello,

@sammyskills


If i move

Code:
<?= session()->has('errors') ? session('errors.no') : ''; ?>
            </span>

top of every input it works everything. I think there is issue related to SESSION

Hello,

I got worked by using old() instead of set_value().

But i can't figure it out why its not worked before. Below code is working

Code:
<?php echo form_open_multipart('') ?>

        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Doc No</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="<?php echo old('no') ?>" name="no"
                    id="basic-default-company" placeholder="1995/23234/3434DF">
                <span class="error">
                    <?= session()->has('errors') ? session('errors.no') : ''; ?>
                </span>
            </div>

        </div>
        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-name">Document Type</label>
            <div class="col-sm-10">
                <select name="doc_type_id" id="doc_type_id" class="form-select">
                    <option value="">Select</option>

                    <?php foreach ($doc_types as $doc): ?>
                        <option value="<?= $doc['id']; ?>" <?= set_select('doc_type_id', $doc['id']) ?>> <?= $doc['name']; ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <span class="error">
                    <?= session('errors.doc_type_id'); ?>
                </span>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Expiry Date</label>
            <div class="col-sm-10">
                <input class="form-control" type="date" value="<?= old('expiry_date') ?>" name="expiry_date" value=""
                    id="html5-date-input">
                <span class="error">
                    <?= session('errors.expiry_date'); ?>
                </span>
            </div>

        </div>

        <div class="row mb-3">
            <label class="col-sm-2 col-form-label" for="basic-default-company">Upload Doc <br /><small>(Allowed JPG, GIF
                    or
                    PNG)</small></label>
            <div class="col-sm-10">
                <input class="form-control" type="file" name="doc_file" id="formFile">
                <span class="error">
                    <?= session('errors.doc_file') ?>

                </span>
            </div>


        </div>

        <div class="row justify-content-end">
            <div class="col-sm-10">
                <button type="submit" class="btn btn-primary">Save</button>
            </div>
        </div>
        </form>


Anyone know what was the problem with set_value() ?