Forums

Default values for registered users

pdenessen 04 Dec, 2008
I have 2 categories of users who will fill in the created form, guests and registered users.

If a registered user has logged in, how can I then copy his (CB)_fields into the fields of the form as default values.
From the registered users, the name, address etc are already stored in the database, and it would be nice if these values would already been filled in as default in the requested fields.

Another option would be that those (for guest required) fields where not shown in the field.

Thanks for you help.

Patrick
GreyHead 04 Dec, 2008
Hi Patrick,

I would write a little code at the beginning of the Form HTLP to check the user ID, look them up in the user & CB_User tables and set default values for the form fields depending on what is found.

Bob
pdenessen 04 Dec, 2008
Thanks Bob,

problem is that I am not yet so familair with this code and learning it. (As might have noticed🙂

Meanwhile I found this Topic and changed my code in this way :


<DIV class="form_item">
<DIV class="form_element cf_textbox" ><LABEL class="cf_label" >Voornaam </LABEL><INPUT class="cf_inputbox required" id="voornaam"  maxLength="150" size="30" name="voornaam" type="text" value="<?php $user = &JFactory::getUser();echo $user->firstname;?>"></DIV>
<DIV class="clear" > </DIV>
</DIV>

<DIV class="form_item">
<DIV class="form_element cf_textbox" ><LABEL class="cf_label">tussennaam </LABEL><INPUT class="cf_inputbox " id="tussennaam"  maxLength="150" size="30" name="tussennaam" type="text" value="<?php $user = &JFactory::getUser();echo $user->middlename;?>"></DIV>
<DIV class="clear" > </DIV>
</DIV>

<DIV class="form_item">
<DIV class="form_element cf_textbox" ><LABEL class="cf_label">Naam </LABEL><INPUT class="cf_inputbox required" id="naam"  maxLength="150" size="30" name="naam" type="text" value="<?php $user = &JFactory::getUser();echo $user->lastname;?>"></DIV>
<DIV class="clear" > </DIV>
</DIV>

<DIV class="form_item">
<DIV class="form_element cf_textbox" ><LABEL class="cf_label" >Adres </LABEL><INPUT class="cf_inputbox required" id="adres" maxLength="150" size="30" name="adres" type="text" value="<?php $user = &JFactory::getUser();echo $user->address;?>"></DIV>
<DIV class="clear" > </DIV>
</DIV>


It is however only working for the emailfield.

Do you have example on how I could set this up ?

Many thanks,

Patrick
GreyHead 04 Dec, 2008
Hi Patrick,

First off, you only need the JFactory line once
<?php
$user = &JFactory::getUser();
?>
Then you can use $user wherever it is needed.

Second, the Joomla user object doesn't know about first_name and last_name, only name, and it doesn't know about address at all.

These items may be in the CB_user table or somewhere else, you'll need to find them and look them up.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger