Checkboxes - Custom Registration Attributes

Permalink
Hi All,

I've setup the attribute content within Concrete5 and have used the following code to display the checkbox in the registration:

<div>
  <?php $newsletter_sub = 'akID[' . UserAttributeKey::getByHandle('newsletter_sub')->getAttributeKeyID() . '][value]'; ?>
        <?php echo $form->label($newsletter_sub, t('Newsletter Subscription')); ?><br/>
        <?php echo  $form->checkbox('Newsletter Subscription','newsletter',true); ?>
   </div>


However, once clicked, it is not saving the value as a user attribute. Any ideas on this?

Also, I want to be able to code in a select box, however I cant find much documentation regarding this?

Concrete5 Version 5.6.x

Thanks

 
hutman replied on at Permalink Reply
hutman
Are you trying to use these within the standard C5 registration form? If so, why aren't you just checking the boxes in the dashboard for show on registration form?
drm92 replied on at Permalink Reply
No, this is a completely custom registration form. Overriding the default one.
hutman replied on at Permalink Best Answer Reply
hutman
I think you have a couple of things missing in your code, I believe it should be like this:

<div>
<?php $newsletter_sub = 'akID[' . UserAttributeKey::getByHandle('newsletter_sub')->getAttributeKeyID() . '][value]'; ?>
<?php echo $form->label($newsletter_sub, t('Newsletter Subscription')); ?><br/>
<?php echo  $form->checkbox($newsletter_sub,1,true); ?>
</div>

The form helper for creating a checkbox is like this

$form->checkbox($name, $value, $isChecked, $tagAttributes);

So what I have there will make the value 1 which is usually the case when you are using a checkbox (boolean) attribute.
drm92 replied on at Permalink Reply
Thanks for the explanation. I see what was happening now!

Could you explain the correct format for the select box at all? I cant seem to get that to even show on the registration form!
hutman replied on at Permalink Reply
hutman
Take a look at this page of the Documentation, it shows how to setup each of the types.

https://www.concrete5.org/documentation/developers/5.6/forms/standar...
drm92 replied on at Permalink Reply
Hi,

For the select, do you have any idea why the following wont save?
<fieldset>
                        <div>
                             <?php $event = 'akID[' . UserAttributeKey::getByHandle('event')->getAttributeKeyID() . '][value]'; ?>
                            <?php echo $form->label($event, t('Select Event Type'))?>
                            <?php echo $form->select($event, array('SOCIAL LEISURE' => 'Social Leisure', 'CHARITY' => 'Charity'), 'CHARITY');?>
                        </div>
                        </fieldset>

Same format as the documentation
hutman replied on at Permalink Reply
hutman
Is your attribute a Select Attribute or is it a text attribute? If it is a select attribute you have to jump through some hoops to match up the select options.
drm92 replied on at Permalink Reply
Its a select attribute, but it can be a text attribute to make it work? This is located within the "Edit Profile" section. I read about setAttribute() playing apart here but still unable to get it working!
drm92 replied on at Permalink Reply
I also cant get the select attribute to work in the Registration? I'm not sure why concrete5 have made a custom select attribute so long winded to program?
<?php $supplier = 'akID[' . UserAttributeKey::getByHandle('Supplier')->getAttributeKeyID() . '][value]'; ?>
        <?php echo $form->label($supplier, t('Are you a Supplier? ')); ?><i class="fa fa fa-info-circle"> </i><br/>
        <?php echo $form->select($supplier, array('No' => 'No', 'Yes' => 'Yes'), 'No'); ?>
hutman replied on at Permalink Reply
hutman
The problem with the select attribute is the naming convention, it should look like this

<?php $supplier = 'akID[' . UserAttributeKey::getByHandle('Supplier')->getAttributeKeyID() . '][atSelectOptionID][]'; ?>
<?php echo $form->select($supplier, array('' => 'Select One', 1 => 'No', 2 => 'Yes'), 1); ?>

Make sure that these are in the exact same order as the options in the dashboard in order to verify that the option values match up correctly.

I agree with you that this is not very programmer friendly, but you always have the option to manually update the user attribute in the controller rather than trying to replicate the standard functionality.
drm92 replied on at Permalink Reply
Tried this code also and it still doesnt want to work! This is the exact same as my dashboard attribute:

<?php $supplier = 'akID[' . UserAttributeKey::getByHandle('supplieruser')->getAttributeKeyID() . '][atSelectOptionID][]'; ?>
<?php echo $form->select($supplier, array('No' => 'No', 'Yes' => 'Yes'), 'No'); ?>


and this translate to the following in the code source

<div>
<select name="akID[30][atSelectOptionID][]" id="akID[30][atSelectOptionID]1"  ccm-passed-value="No" class="ccm-input-select"><option value="No" selected="selected">No</option><option value="Yes" >Yes</option></select>   </div>


I have also added "Required on Registration" and this error message appears every time as its obviously not receiving a value!

I can't believe a select box is so difficult compared with the other input options!
hutman replied on at Permalink Reply
hutman
Change it to this, as I showed in my previous example

<?php $supplier = 'akID[' . UserAttributeKey::getByHandle('supplieruser')->getAttributeKeyID() . '][atSelectOptionID][]'; ?>
<?php echo $form->select($supplier, array('0' => 'No', '1' => 'Yes'), '0'); ?>
drm92 replied on at Permalink Reply
Tried this and altering it a few times, but still can't seem to get it to work. Does it matter which version of Concrete5 im runing? Its 5.6 not 5.7
hutman replied on at Permalink Reply
hutman
Please provide a screenshot of the attribute setup in the Dashboard and the exact code snippet that you have on the front end.
drm92 replied on at Permalink Reply
http://i.imgur.com/u8HCGyZ.png

http://i.imgur.com/TKnCFsx.png
hutman replied on at Permalink Reply
hutman
That all appears to be correct, the only other thing I can think of is that the select option ids aren't 0 and 1, the only way to check that would be to go into the Dashboard edit screen and open your developer tools and see what the id is from there.
drm92 replied on at Permalink Reply
Dashboard Edit Screen - > Developer Tools? Where would that be on 5.6? Im guessing that is a 5.7 thing?
hutman replied on at Permalink Reply
hutman
It's a browser thing, like if you're using Firefox there is Firebug, if you are using Chrome hit F12 and the Developer Tools will come up.
drm92 replied on at Permalink Reply
Oh Sorry - I usually call it "inspect element". Indeed the ID's were different, this is the code that is produced when you set it to concrete5's default

<select name="akID[30][atSelectOptionID][]" id="akID[30][atSelectOptionID]1"  ccm-passed-value="8" class="ccm-input-select"><option value="" >** None</option><option value="7" >No</option><option value="8" selected="selected">Yes</option></select>


and this is the code that is output when I use a custom way as you stated above
<label for="akID[30][atSelectOptionID][]" class="control-label">Are you a Supplier? </label><a data-toggle="modal" data-target="#supplierModal"><i class="fa fa-info-circle fa-1x"></i></a></i><br/>
        <select name="akID[30][atSelectOptionID][]" id="akID[30][atSelectOptionID]1"  ccm-passed-value="7" class="ccm-input-select"><option value="7" selected="selected">No</option><option value="8" >Yes</option></select>
hutman replied on at Permalink Reply
hutman
That looks like it should work to me. Does it?
drm92 replied on at Permalink Reply
It did! However, I also had to click "Show on Registration Form.", which normally brings up concrete5's default selectbox, but for some reason it doesnt now. Im guessing this is because of the correct values? Thanks for your help, much appreciated!