L
L
lesh_a2019-03-29 18:26:53
PHP
lesh_a, 2019-03-29 18:26:53

How to implement the publication of content through the database on clicking the checkbox?

There is a form in which values ​​are entered from the database, there is a button that adds a new input. There are two problems. I don’t know how to make it so that an empty input is added, and not with the first value from the database. The second problem is that I can not figure out how to implement the publication of these numbers by checkbox. They are displayed on another page through the database, but if the checkbox is not pressed, then they are not displayed. The principle is this.

<?php foreach($numbers as $number):
                            if($number->user_id == $_SESSION['user_id']):
                            ?>
                        <div class="form-group" id="phone">
                            <div class="controls">
                                <input type="checkbox"  name="publish_phone[]" id="publish"  > <label>Publish field</label>
                                <input type="text"  class="form-control"  name="numbers[]"  id="number"   value="<?php echo $number->number; ?>">
                            </div>
                        </div>
                        <?php
                        endif;
                        endforeach; ?>

$(document)
        .ready(function () {
            const variant = $('#phone')
                .clone(true);
            const variant2 = $('#emails')
                .clone(true);
            $('#add')
                .click(function () {
                    $(variant)
                        .clone(true)
                        .appendTo('#variants')
                        .fadeIn('slow')
                        .focus();
                });
            $('#add2')
                .click(function () {
                    $(variant2)
                        .clone(true)
                        .appendTo('#variants2')
                        .fadeIn('slow')
                        .focus();

                });
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rurik Rostislavich, 2017-01-09
@Nickname-no

Toaster is correct in general.
And this is the same amorphous name as Habrahabr

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question