Saturday, August 29, 2009

Re: Form with saving of true/false/null

null will become same as false, 0 and empty string on form submission.
That's the problem.

If these 3 states has so much sense I prefer to use string values:
'yes', 'no' and 'n/a' -- as cake inserts default value '0' and if it
is allowed value not filled option will be considered as filled with
'0' on form validation.

On Aug 1, 9:16 pm, Antônio Marco <idelfonso.alme...@gmail.com> wrote:
> I would use delocalizer's idea just changing the $optarray to:
>
> ('0' => 'No', '1' => 'Yes', 'null' => 'No info')
>
> Good look.
>
> On Jul 31, 7:33 am, delocalizer <conrad.leon...@hotmail.com> wrote:
>
>
>
> > As for the coding, just use the form helper's automagic radio input:
> > eg
> > <?= $form->input('fieldname',array('type'=>'radio','options'=>
> > $optarray)); ?>
> > $optarray is the array of options, eg. array
> > ('0'=>'No','1'=>'Yes','2'=>'No info') for the example you give.
>
> > On Jul 31, 8:29 pm, delocalizer <conrad.leon...@hotmail.com> wrote:
>
> > > The other way you can approach clearing radio input groups is to add
> > > some little button or widget next to each group with a javascript
> > > onClick function that sets the values to empty. At least that's what I
> > > do. It looks prettier & and a bit more logical than an extra radio
> > > option.
>
> > > cheers,
> > > Conrad.
>
> > > On Jul 31, 4:13 pm, Kanten <anders.ho...@gmail.com> wrote:
>
> > > > I have been giving this some thought and I do get what you mean, but
> > > > it is very important that the user can always change e.g. an "yes"
> > > > answer into "not info on subject". Database wise I think you are
> > > > right, that I should define three different values (no = 0, yes = 1,
> > > > no info = 2) instead of using no info = Null.
>
> > > > Thank you very much for your help.
>
> > > > /Anders
>
> > > > On Jul 30, 9:41 am, delocalizer <conrad.leon...@hotmail.com> wrote:
>
> > > > > You sure you want an explicit third option 'no information on the
> > > > > subject'? Wouldn't it be better to just have a radio group with 2
> > > > > buttons (Yes/No or True/False) with a default value of NULL for that
> > > > > field in your database? Or if you really want to have a third option
> > > > > to force a user to enter something, mapping to a value other than
> > > > > empty string or 'null' might be wise, as depending on how your db
> > > > > field is defined, these may not be distinguishable from 'no data
> > > > > entered'. The 'right' solution really depends on the particular logic
> > > > > of your application - what data your users should enter and how that
> > > > > data will be used and analysed once it's in the database.
>
> > > > > On Jul 30, 12:40 am, "Richard@Home" <richardath...@gmail.com> wrote:
>
> > > > > > I'd use a drop down select instead of an option group.
>
> > > > > > This should do the trick:
>
> > > > > > <?php echo $form->input("Model.field", array("options"=>array(""=>"No
> > > > > > information on subject", true=>"True", false=>"False))); ?>
>
> > > > > > On Jul 29, 12:29 pm, Kanten <anders.ho...@gmail.com> wrote:
>
> > > > > > > Is there really noone, that can help me with this one?
>
> > > > > > > Thanks
> > > > > > > Anders
>
> > > > > > > On Jul 10, 1:49 pm, Kanten <anders.ho...@gmail.com> wrote:
>
> > > > > > > > Hi,
>
> > > > > > > > I am making a database for research and for this project I have a lot
> > > > > > > > of dichotomous (binary) variables where I need to be able to
> > > > > > > > discrimate between true, false and "no information on
> > > > > > > > subject" (=null). I would like to store it as a bool field in MySQL.
> > > > > > > > User interface wise I was thinking of using radio buttons with the
> > > > > > > > option of choosing between the three posibilities.
>
> > > > > > > > Is there some easy way of doing this using the builtin form helper, or
> > > > > > > > do I need to to modify it somehow?
>
> > > > > > > > Thanks
> > > > > > > > Anders
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: