S
S
Sandwich212020-04-27 02:43:13
PHP
Sandwich21, 2020-04-27 02:43:13

Passing values ​​from checkbox?

I have multiple checkboxes on a page,

<input type="checkbox" name="person[]">
<input type="checkbox" name="person[]">

I can fill them out while on the page. But when the page is updated, the notes naturally fly off.
I would like that after I filled in all the checkboxes, the data was remembered. But the problem is that you just need to poke into a few checkboxes and so that when you reboot, these checkboxes remain marked and somewhere the data about which checkboxes I marked were saved. I tried to pass them to the POST array, but for this I need to complete the form and the submit button, which will have to be additionally clicked, and I need to poke into the checkboxes -> refresh the page -> get the numbers of these checkboxes.
I understand that there is an interaction between JS and PHP, but I still don’t understand how to implement it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arseny, 2020-04-27
@Sandwich21

1. If by reload you mean just a reload and not a submitted form → use sessionStorage. It's just JS.
2. If you want data to come to you after submitting the form, its validation and processing, you need to have a storage of this data on the server side. Usually, this role is played by databases with users, bindings, etc., and here a great solution would be to use a framework in PL, in which there will be either forms, with which you save data in the model when loading this form again (say, editing anything), you will get a prepopulated form.
3. If you want to drive the form without any checks, simply passing data to POST \ GET, leading there with the form submission, then you need to generate a document generation using a PL that will parse the request and be able to do it tritely like this:

<input type="checkbox" checked="<?= $field[3] != true ?: 'checked' ?>">...

or parse the JS request and already distribute the values ​​in the loaded page.
In other words, it all depends on the end goal.

S
scottparker, 2020-04-27
@scottparker

in order for the checkboxes not to fly off,
you can use the ajax technology, which will execute the request (send data) without reloading the page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question