Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter v4.5.0 Released!
#31

Need Help
I'm facing session related issue

Once the user change the option, the other select tag's option will be dynamically add via ajax

HTML
Code:
<!-- New Program Details -->
        <div class="col-12 col-md-6 col-lg-4 col-xxl-3">
            <div class="form-group mb-3">
                <label for="institute" class="mb-2">Institute</label>
                <?php $institutes = $appLib->getInstituteList(); ?>
                <?= form_dropdown('institute', $institutes, '', 'id="institute" class="custom-select-2 mb-2" data-width="100%" required ') ?>
                <span class="text-capitalize error-span text-danger ms-1 my-2 d-none"></span>
            </div>
        </div>
        <div class="col-12 col-md-6 col-lg-4 col-xxl-3">
            <div class="form-group mb-3">
                <label for="degree" class="mb-2">Degree</label>
                <?php $degrees = $appLib->getDegreeList(); ?>
                <?= form_dropdown('degree', $degrees, ' ', 'id="degree" class="custom-select-2 mb-2" data-width="100%" required') ?>
                <span class="text-capitalize error-span text-danger ms-1 my-2 d-none"></span>
            </div>
        </div>

JS
Code:
function getDegreeList(inst_id) {
$.ajax({
url : base_url + 'app/getDegreeList',
type: 'POST',
data: {#post_data},
  dataType:'html',
success: function(data) {
$('#selectTag').html(data);
},
error: function(xhr,status,err) {
console.log('xhr => ',xhr,' Status => ',status,' Err => ',err);
},
});
}

Once the data from the server has added to the select tag, i have submit my form, the session()->flashdata() did not works
PHP Code:
session()->setFlashdata() 

If i'm not dynamically add options to the select tag, the below code works
PHP Code:
session()->setFlashdata() 


Why i am facing this ?
Reply me to this thread
Reply
#32

It appears you are trying to add session data using Ajax and that is failing. That would make this an Ajax or JavaScript issue..

You might be better off trying a JavaScript support forum. Personally, I try to use frameworks such as Codeigniter to avoid JavaScript whenever possible.
Reply
#33

It looks like your page is not reloading after returning the HTML object in $('#selectTag').
As far as I know, flashdata is only shown at page load. You can add additional data as result of the ajax post and use this to call a modal or a toast.
Reply
#34

(This post was last modified: 05-09-2024, 05:18 AM by LP_bnss.)

I have more input tags in that form, but i had only showcase two select tags

In my case
When user submit the form, ajax can takes responsible to call the controller and,
  • If validation is true, the data will be inserted to the DB and then it will reloads the current page from the controller.
  • If validation is false then i return the validation error as JSON Format to the ajax.

(05-09-2024, 04:01 AM)Bosborne Wrote: It appears you are trying to add session data using Ajax and that is failing. That would make this an Ajax or JavaScript issue..

You might be better off trying a JavaScript support forum. Personally, I try to use frameworks such as Codeigniter to avoid JavaScript whenever possible.

I have already worked with CI3, the same concept works in CI3 but in CI4 why i can't achieve this
Reply
#35

(04-25-2024, 12:35 AM)kenjis Wrote: @eelisland It is a known problem.

Note: Unfortunately now the User Guide on the official site is not yet updated due to the deployment trouble.

https://github.com/codeigniter4/CodeIgni...ssues/8757

@kenjis 

Thank you for getting the User Guide on the official site updated.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB