Jump to content

setValue for checkboxes FormField not working to get it 'checked'


Fewl
 Share

Recommended Posts

Hi, 

I am using PS 1.7.6.3

I have this hook to add a checkbox to the registration form which works fine on the account creation form: 


    public function hookAdditionalCustomerFormFields() {
        if($this->context->customer->getGroups()[0] == 4) $v = true;
        else $v = false;

        return [
                    (new FormField)
                    ->setName('professionnal_group[]')
                    ->setType('checkbox')
                    ->setValue($v)
                    ->setRequired(true)
                    ->setLabel($this->l('Je suis un professionnel')),
        ];

    }

Unfortunately, the setValue field is never passed to the tpl (below), even when I just hardcode the value to 1 so it's never checked! Kind of an issue on the form when the user 'edit' his account

   {elseif $field.type === 'checkbox'}

        {block name='form_field_item_checkbox'}
          <span class="custom-checkbox">
            <label>{$field.availableValues}
              <input name="{$field.name}" type="checkbox" value="1" {if $field.value}checked="checked"{/if} {if $field.required}required{/if}>
              <span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
              {$field.label nofilter}
            </label>
          </span>
        {/block}

Thanks for your help. 

 

Share this post


Link to post
Share on other sites

  • 1 year later...
  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More