V
V
Vasyl Vandych2021-06-18 16:10:09
PHP
Vasyl Vandych, 2021-06-18 16:10:09

How to make a dependent select list based on the data inside?

How can I make a dependent select list based on the select data?
I wrote the first part of the list, but the second part does not want to be shown through value, I don't understand how to write php code correctly.

<?php $biolink_pages = require APP_PATH . 'includes/biolink_pages.php'; ?>
<div class="form-group">
<label for="settings_pages"><i class="fa fa-fw fa-user fa-sm mr-1"></i> <?= language()->link->settings->font ?></label>
<select id="settings_page_type" name="page_type" class="form-control">
<?php foreach($biolink_pages as $key => $value): ?>
<option value="<?= $key ?>" <?= $data->link->settings->page_type == $key ? 'selected="selected"' : null?>><?= $key ?></option>
                                    <?php endforeach ?>
                                </select>
                            </div>


this piece of code is displayed and written to the database, but when I try to pull out other values ​​from page_type, it does not write, it only displays. biolink_pages.php

file code

<?php

return [
    'businesses' => [       
    ],

    'community_organization' => [
    ],

    'interest' => [
    ],

    'media' => [
    ],

    'public_figure' => [
        'actor',
    'artist',
    'athlete',
    'author',
    'band',
    'blogger',
    'chef',
    'comedian',
    'dancer',
    'designer',
    'fashion-designer',
    'digital-creator',
    'editor',
    'entrepreneur',
    'fashion model',
    'film-director',
    'fitness model',
    'gamer',
    'journalist',
    'motivational-speaker',
    'musician',
    'musician-band',
    'news personality',
    'orchestra',
    'producer',
    'scientist',
    'spiritual-leader',
    'sports-promoter',
    'talent-agent',
    'video-creator',
    'writer'
    ],
];


here is a piece of code that is displayed, but does not write the value, + is not tied to the choice of the first

<div id="" class="form-group">
                                <label for="settings_pages"><i class="fa fa-fw fa-user fa-sm mr-1"></i> <?= language()->link->settings->font ?></label>
                                <select id="settings_page_category" name="page_category" class="form-control">
                                    <?php foreach($biolink_pages['public_figure'] as $page_category): ?>
                                        <option value="<?= $page_category ?>" <?= $data->link->settings->page_category == $page_category ? 'selected="selected"' : null?>><?= $page_category ?></option>
                                    <?php endforeach ?>
                                </select>
                            </div>


It is necessary that when choosing public_figure, a list appears with values ​​inside, as well as for other choices.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-06-18
@ThunderCat

here is a piece of code that is displayed, but does not write the value
Perhaps it does not lie in the same form as the first select?
+ is not tied to the choice of the first
How did you try to bind it? You stupidly brought one more select to the page, didn't you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question