Add address attribute programtically

Permalink
Hi all,

I am currently styling up my profile pages by adding in User Attributes programmatically like such:

<div class="one_half last">
             <div class="name-field">
                <?php $fieldName = 'akID[' . UserAttributeKey::getByHandle('lastName')->getAttributeKeyID() . '][value]'; ?>
                <?php echo $form->label($fieldName, t('Surname:')); ?>
                <?php echo $form->text($fieldName); ?>
            </div>
          </div>


But am getting stuck on how to add the address and select boxes this way... Is there anyone nice person out there able to shed some light on this?

 
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
If you are trying to display the attribute values, then why do you use form elements? Simply display it directly.

Rony
JohntheFish replied on at Permalink Reply
JohntheFish
You don't need code. You can just add the attributes via the dashboard to a user and tick the checkbox to 'edit in profile'.
mobius2000 replied on at Permalink Reply
Sorry if I'm over complicating it... All those dashboard added User Attributes can thrown in a
foreach($attribs as $ak) { ?>
, I'm trying to add them individually to my custom registration page to give me more control over each item as the registration question page is quite long.
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
$ui = UserInfo::getByID($uID);
print $ui->getAttribute('attribute_handle');
mobius2000 replied on at Permalink Reply
I have no doubt that I've added something wrong... I'm a bit of a noob when it comes to this but I am getting a error with this...
Fatal error: Call to a member function getAttribute() on a non-object in /xxxx/xxxx/xxxx/single_pages/register.php on line 81


This is what I added to my registration/php singlepage
<div class="two_third"><?php $ui = UserInfo::getByID($uID); print $ui->getAttribute('resAddress'); ?></div>


I'm sorry for being such a pain and very grateful to everyone throwing in responses.
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
I'm confused whether you are trying to customize the profile page or registration page. There is little difference between them. If you are in register page, then you don't have any user logged in, so no user object found. But in case of profile page, there is an user object that you can use automatically.

Rony
mobius2000 replied on at Permalink Reply
Ha.... I see now.

I will actually be doing both so the code above will be fine for the profile edit page but not the register page?
mobius2000 replied on at Permalink Reply
Ok, I'm not meaning to be difficult but the same original question is leading me to an even bigger one.

I'm not entirely sure I'm heading down the right track for this but hopefully if I explain exactly what I'm trying to achieve some kind folks might be able to give me some pointers.

Ok, I'm creating a site for a temp agency and the client wants to be able to have a registration for which goes into lots of things from as simple as name, email etc etc right through to a 20 point checkbox of trained skills. They also want to have expiration dates for their works truck licenses etc etc... This is becoming bigger than I originally expected.

So the clients need to be able to filter through registrants based on some key criteria has lead me to using the public registration feature as a lot of what I need is ready to go (kind of).

So I have created my registration page at root/single_pages/register.php and created a few test User Attributes such as 'firstName' and 'lastName'. As expected these all pop up in the:
<?php 
   $af = Loader::helper('form/attribute');
   foreach($attribs as $ak) { ?> 
         <?php echo  $af->display($ak, $ak->isAttributeKeyRequiredOnRegister());   ?>
   <?php  }?>

area but looking at what is generated, it just spits out the 'User Attributes' in rows down the page. Typically fine for basic registration, this won't work for the amount of questions I need to ask as the page will be miles long and ugly.

So this is where I cam to my original question of manually adding in each User Attribute (some required, some are up to the user).

Questions:

1./ Am I at least thinking in the right way or is this way to complicated for the registration system to handle.

2./ Can anybody help with what code I should use for laying out each question manually? I'm CERTAINLY NOT asking for someone to do it, just hoping for some references that I can replicate for basic text inputs, date inputs, select and addresses in regards to User Attributes

3./ Finally, even in my most basic test of using the original 'foreach' method of generating the page, the date attribute doesn't work unless I have the page in edit mode, it simply shows up as text box when not in edit mode.

I know I am asking a lot but if anyone can take the time to help, I'd be happy to buy them a coffee via a paypal donation :-)