How to make boolean field from checkbox type form

930 views
Skip to first unread message

Diego Baratta

unread,
Dec 4, 2015, 2:24:03 PM12/4/15
to redbeanphp
I think the title is pretty explicit. How can i do that? Because I did a form with checkboxes and the "store" function makes the table with varchar fields from it, writing "on" in case that it's checked and "NULL" otherwise.

PD: I'm extremely noob with redbean, this is my first use of it.

gabor

unread,
Dec 4, 2015, 5:41:10 PM12/4/15
to redbeanphp

Hi there,

You'll have to convert the value to 'true' or 'false' before storing it in the database.
However, if you want your form to be stored in a 'one-run' you can also use radioboxes instead of checkboxes and
fill those radio values with 0 and 1. Personally I think radio buttons are more applicable for booleans than checkboxes, I prefer checkboxes for 'actions' to perform on a 'post', so
in my apps their values never end up in the database - just sharing personal approach here...

cheers,
Gabor

sah

unread,
Dec 5, 2015, 11:08:02 AM12/5/15
to redbeanphp
I do it like this:

<input type="hidden" name="dialog[enabled]" value="0">
<input id="person-enabled" type="checkbox" name="dialog[enabled]" checked="checked" value="1">

and then use either R::graph() or R::dispense().

ciobotel

unread,
Apr 20, 2017, 4:57:16 AM4/20/17
to redbeanphp
in google form where is :'input field -hidden' ?

anton slesarev

unread,
Dec 11, 2017, 1:14:46 PM12/11/17
to redbeanphp
зачем тебе там создавать логическое поле? можно с помощью проверки на пустоту! вот например
<?php
 $data = $_POST['bool'];
if(empty($data['bool'])){$i = false} else {$i = true}
?>
//если выбрать флажок то i = правда иначе i = лож
 <input type="checkbox" name="bool" value="qwe">qwe<Br>
Reply all
Reply to author
Forward
0 new messages