Forums

Profile data in the form

loadlucas 10 Nov, 2015
Hello everybody

I try to add some data from the user profile in my form in order to send it with some "extra" data.

I receive infos that help me to add the user name and the user email to the form adding these custom code in Designer part :
<?php
$user =& JFactory::getUser();
$name = '';
$email = '';
$readonly = '';
if ( $user->id > 0 ) {
  $name = $user->name;
  $email = $user->email; 
    $readonly = "readonly='readonly'";
}
?>
<div class="gcre-input gcore-display-table" id="name_container_div" style="">
  <label for="name">Nom</label>
  <input id="name" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $name; ?> " name="name" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-name"></div>
</div>
<div class="ccms_form_element cfdiv_text" id="email_container_div" style="">
  <label for="email">Email</label>
  <input id="email" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $email; ?> " name="email" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-email"></div>
</div>


I try this to add address1 in but no effect :

<?php
$user =& JFactory::getUser();
$name = '';
$email = '';
$address1 = '';
$readonly = '';
if ( $user->id > 0 ) {
  $name = $user->name;
  $email = $user->email;
 
    $readonly = "readonly='readonly'";
}
?>
<div class="gcre-input gcore-display-table" id="name_container_div" style="">
  <label for="name">Nom</label>
  <input id="name" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $name; ?> " name="name" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-name"></div>
</div>
<div class="ccms_form_element cfdiv_text" id="email_container_div" style="">
  <label for="email">Email</label>
  <input id="email" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $email; ?> " name="email" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-email"></div>
</div>
<div class="ccms_form_element cfdiv_text" id="email_container_div" style="">
  <label for="address1">Adresse</label>
  <input id="address1" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $address1; ?> " name="address1" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-address1"></div>
</div>


I try these code in another custom code with no effect too ...
    <?php 
    if ( isset($form->data['address1']) && $form->data['address1'] ) {
      $address1 = $form->data['address1'];
    } else {
      $user =& JFactory::getUser();
      $address1 = $user->address1;
    }
    ?>
    <input type='text' name='address1' id='address1' value='<?php echo $address1; ?>' /> 


Maybe that's not the good variable to find the "adress1", "zip", .... of the user profile

Any ideas ?

Thanks

Loadlucas
loadlucas 10 Nov, 2015
Found it ...
iadd this in custom code :

<?php
jimport( 'joomla.user.helper' );
$user =& JFactory::getUser(); 
$userId = $user->id; 
$userProfile = JUserHelper::getProfile( $userId );
$name = '';
$email = '';
$readonly = '';
if ( $user->id > 0 ) {
  $name = $user->name;
  $email = $user->email; 
    $readonly = "readonly='readonly'";
}
?>
<div class="gcre-input gcore-display-table" id="name_container_div" style="">
  <label for="name">Nom</label>
  <input id="name" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $name; ?> " name="name" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-name"></div>
</div>
<div class="ccms_form_element cfdiv_text" id="email_container_div" style="">
  <label for="email">Email</label>
  <input id="email" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $email; ?> " name="email" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-email"></div>
</div>
<div class="ccms_form_element cfdiv_text" id="address1_container_div" style="">
  <label for="address1">Adresse</label>
  <input id="address1" maxlength="150" size="30" class="" 
    title="" value=" <?php echo $userProfile->profile['address1']; ?> " name="address1" 
    type="text" <?php echo $readonly; ?> />
  <div class="clear"></div>
  <div id="error-message-address1"></div>
</div>


Hope it help ...

Thanks,

Loadlucas
GreyHead 10 Nov, 2015
Hi loadlucas,

Please see this FAQ - usually you only need to get this in the On Submit event.

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