New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with checkbox and hidden fields #85
Comments
What do you mean by "I miss the checkbox?" Your code outputs the following <div id="_agree" class="form-check">
<input checked type="checkbox" name="agree" id="agree" value="agree" class="form-check-input">
<label class="form-check-label" for="agree"> I Agree</label>
</div> I don't see an issue here... The |
The issue with the checkbox:
HTML
This issue is fixed with commit: ba65356 |
The issue with checkbox isn't fixed complete.
After the first run with V 1.2.3 I get the following (box checked):
I miss the value for |
The 7th parameter of the checkbox method is boolean; it's Regardless, if we strip your code down to the basics, we're basically telling the checkbox is if it should be checked or not. We don't need to pass a 'checked' string, as Formr will take care of this for us, all we need to do is pass it a
Produces the following HTML (the checkbox is unchecked) <label for="agree">
<input type="checkbox" name="agree" id="agree" value="1"> I Agree
</label> If we change $checked = 1;
$form->checkbox('agree','I Agree','1','agree','','',$checked); we get the following (the checkbox is checked) <label for="agree">
<input checked type="checkbox" name="agree" id="agree" value="1"> I Agree
</label> It's working as it should. EDIT: to make your code more streamlined you could just omit all the checks, and since $form->open();
$form->csrf();
$form->checkbox('agree', 'I Agree', '1', 'agree', '', '', $setting_checked);
$form->submit_button('Submit Form');
$form->close(); |
I can't agree that's working. After the first submit the state is checked, but the checkbox is unchecked. Please test the script with checked and unchecked button.
If I use the more forms for setting site (last function with the commit on 24 May), the site will work. After the upgrade to Version 1.2.3 the checkbox will not work. Suspicious is, that the forms with more elements returned after the second submit the correct value. |
Let's boil this down to the most basic elements. $form = new Formr\Formr(');
require 'Formr/class.formr.php';
$form = new Formr\Formr();
$form->open();
$form->checkbox('agree', 'I agree to the terms', 'agree');
$form->submit_button();
$form->close(); If you tick the checkbox and submit the form, the checkbox is checked. If you uncheck the checkbox and submit, it's no longer checked. It's working as intended, therefore, the issue is mostly likely with your code. Are you using a $_SESSION? |
With a session cookie isn't it better. I use a htpasswd authentication (basic) for the authentification in apache2.
The output of this code:
this is my issue. After the submit, I get the checkbox unchecked back. After every submit is the checkbox unchecked (with checked before).
The code of the testpage:
PHP Version: 7.3.19 - apache2 - Raspbian OS |
I found the problem. It's not actually with the checkboxes, it's with csrf. If you remove that the checkbox will work as intended. I'll work on this today and push an update. Thanks! |
Thank you for very much for your great work.
In the last days I update a project to the newest version 1.2.2.
I have an issue with the creation of a checkbox:
I miss the checkbox, it's similar to the issue #83.
The version 1.2.1 will work. At the moment I have downgrade to 1.2.1.
Another issue (version 1.2.1/1.2.2):
The CSRF hidden box will be present in the source code of the page and the hidden box with the
Name
will be not present. I can't find anything.Please check this and have a nice weekend.
The text was updated successfully, but these errors were encountered: