how to get a checkbox checked by default ?

we have piece of code below with a checkbox
but we would like to have the checkbox checked by default on the user form

how can we achieve this please ?
Thanks for advising.

[php] array(
‘form_id’ => ‘global_settings’,
‘id’ => ‘visitors_counter’,
‘element’ => ‘checkbox’,
‘label’ => $this->(‘Visitors Counter’),
‘multiOptions’ => array(
1 => null,
),
‘description’ => $this->
(‘Check the above checkbox to display the “Item Viewed” box on the listings details pages’),
),
[/php]

Hello.

[php]A checked checkbox[/php]

?

thanks for the hint.
We know how to do some coding, but on this item / domain of coding we are completely new, so probably we are asking stupid questions :wink:

We tried it to fit your code into the existing array (see our orginal post) but that will rather create a new checkbox than setting the existing one in our code to status checked ?

So what we need : when a user opens the form, the existing checkbox should be checked by default (and the user can uncheck it if he or she wants).

Thanks in advance for your further help.

[php] array(
‘form_id’ => ‘global_settings’,
‘id’ => ‘visitors_counter’,
‘element’ => ‘checkbox’,
‘label’ => $this->(‘Visitors Counter’),
‘multiOptions’ => array(
1 => null,
),
‘description’ => $this->
(‘Check the above checkbox to display the “Item Viewed” box on the listings details pages’),
),
‘checked’ => ‘checked’,
),
[/php]

thanks for this hint too. Really appreciate it.

We tried (and some variants of it too) but unfortunately (on the user form) it doesn’t mark the checkbox yet
Although the code probably is very close to the solution, as we do not get an error on it either.

Thanks in advance for further suggestions on this code suggestion or othter solution.

What is the html that is being output by the array with the change?

thanks for your effort to help

the url is www.superkoopjes.be/register
(you can swith the language to English on the site + the checbox we would like have checked is 'Subscribe to newsletter, near the end of the registration form)

so in other word we have tried to implement your suggestion in following code
array(
‘form_id’ => ‘basic’,
‘id’ => ‘newsletter_subscription’,
‘element’ => ‘checkbox’,
‘multiOptions’ => array(
1 => $translate->_(‘Subscribe To Newsletter’),
),
‘checked’ => ‘checked’,
),

Are you using a framework for this?

[php]array(
‘form_id’ => ‘basic’,
‘id’ => ‘newsletter_subscription’,
‘element’ => ‘checkbox’,
‘checked’ => ‘checked’,
‘multiOptions’ => array(
1 => $translate->_(‘Subscribe To Newsletter’),
),
)[/php]

That should work, but if the parser you are using is validating and that option is NOT in it, it will always remove it from the output.

i’m a newbie so maybe this post is beyond my understanding, yet I am confused by this code. isn’t this a logical matter?
the checked attribute has no values so ‘checked’ => ‘checked’ seems like you are saying checked=“checked”.
I don’t understand how this could work. it is like a boolean operator, yes? checked = true since checked has no value like required. Am I wrong?

sorry if this post is of no help. :frowning:

thanks again for the advice
I tried to put the ‘checked’ line on the suggested place in the code, but unfortunately the checkbox is still not ticked

so as you suggested, now I should start looking towards the “parser”
but being newby to this…the unavoidable question sounds of course ::slight_smile: how can we modify the parser to avoid that the parameter ‘checked’ is rejected ? thanks in advance for bringing us an other step closer to understanding and solving of the problem.

best regards,
Spring

This thread is lacking a frame of reference upon which to help.

astonecipher asked the following, which wasn’t answered -

Are you using a framework for this?

Without knowing what the definition of this array is or how it is being processed to produce the html, there’s no way to know what the syntax should be, or if it is even possible (without modifying the code), to cause a check-box form field to be checked.

I suspect, based on the _(…) method that this is the e107 cms, but without knowing exactly what this is part of, there’s no way to solve the problem.

No, there is no framework in this bought progam (that we are customizing in some parts).

but the good news : we just found the solution and will share it here below of course.
Thanks again for everyones help and hints. It kept us trying and trying, and finally to find the solution.

         array(
             'form_id'      => 'basic',
             'id'           => 'newsletter_subscription',
             'element'      => 'checkbox',
      [b]  'value'        => 1,[/b]
             'multiOptions' => array(
                 1 => $translate->_('Subscribe To Newsletter'),
             ),
         ),
Sponsor our Newsletter | Privacy Policy | Terms of Service