Forums

Custom field from CB to chronoform

ExSpiit 29 May, 2008
I am searching for any code sample but can't find any.

I use CB and when someone registers, he writes his name, city, country, zipcode, phone,...

Now I would like to have form, when member opens it fields like "Phone", "Zip", "Country", "City",... will be filled out already taken from his CB profile. How can I do that?

I managed to get his full name or email with "value="<?php echo $my->email?>", buw how can I get other fields? I tried something like "value="<?php echo $my->zipcode?>"" but that doesn't show any data at all.
GreyHead 29 May, 2008
Hi ExSpiit,

I don't use CB so can't tell you exactly what code to use here - it's similar to the $my-> code you have here. I think that if you search the forums you will find it from some months ago.

Bob
ExSpiit 29 May, 2008
I searched and checked all topics with "CB", "profile page", "custom field" or "community builder" search terms. Still no luck on getting the value.

In Forms management there's "Joomla Registration", "CB Registration" and "Profile Page" buttons. What are those used for? I selected "Profile Page" and selected "jos_comprofiler" - I'm not sure what to write and how to use that param then on the code to get one of those values.
GreyHead 29 May, 2008
Hi ExSpiit,

'CB Registration' is ChronoForms PlugIn to use a ChronoForm for for CB registration. I'm afraid that I don't know much more about it than that.

Here is a post where Max explains how to get info from the CB table with the Profile Plugin.

Bob
ExSpiit 29 May, 2008
That doesn't help. He didn't wrote any information of how to show members custom field in form, like for email value="<?php echo $my->email?>".
GreyHead 29 May, 2008
Hi ExSpiit,

As I understand it you just put for example {job_title} in your form, so {email} if that is the column name.

Bob
ExSpiit 29 May, 2008
If I write
value="<?php echo $my->{zipcode} ?>"

Nothing is shown in field. It's empty.
GreyHead 29 May, 2008
Hi Exspiit,

I'm not sure where you are putting that but try value="{zipcode}"

I've lost track of what you are doing here - I'm trying to do too many things at once.

Bob
ExSpiit 29 May, 2008
If I write value="{zipcode}" then field is filled with "{zipcode}".

If you check this tutorial - http://www.chronoengine.com/content/view/32/39/

you have:
<label for="fromname">Name : </label>
<input type="text" name="fromname" id="fromname" tabindex="510" 
value="<?php echo $my->name?>"<?php echo $readonl?> /><br />
<label for="fromemail">Email : </label><input type="text" 
name="fromemail" id="fromemail" tabindex="511" 
value="<?php echo $my->email?>"<?php echo $readonl?> /> 
<br />
I want to add below those fields new fields like Address, city, country, zipcode, phone,... and those values will be taken by already entered data from CB database.
ExSpiit 30 May, 2008
:( Still no success. I even tried "CB Registration" plugin and it doesn't help. Looks like it can't be done in a simple way.
GreyHead 30 May, 2008
Hi ExSpiit,

Sorry, I'll need some time to look at this properly, I may need to install CB and work it all through, Hopefully I'll be able to do that over the weekend.

Bob
ExSpiit 30 May, 2008
Cool, I can't wait. I hope that you will find the solution.
GreyHead 31 May, 2008
Hi ExSpiit,

Hopefully this does it.

I installed the basic bit of CB so that I have a joc_comprofiler table.
Then I added some data, specifically a user with an id of 62 and a zipcode of 29830.

I created a clean copy of the test_form in Joomla 1.5.

In the Form Manager select the form and click the Profile Page Plugin link. There's a form with three fields. Select jos_comprofiler in the first; I added cb_id (any valid name is OK) in the second; and selected the 'id' field in the third (this lets me access the data by Joomla id).

Next open the form, go to the PlugIn tab and check the Profile Page plugin.

In the Form HTML tab add a couple of fields to the Form HTML, I used this:
Name: <input name="name" value="" type="text"><br />
E-mail: <input name="email" value="" type="text"><br />
{zipcode} {id}
<input name="submit" value="Submit" type="submit">
Save the form.

If I go to the form then - provided that I am logged in at the front-end (it's not enough to be logged in as admin in the back-end) I see the info.

If I'm not logged in then I do see the {zipcode} {id} so some error-checking is required.

Bob

ExSpiit 01 Jun, 2008
GreyHead you rockπŸ™‚

This works great. I only need it for logged in users, so it's OK even if it's shown "{fieldname}" if they are logged out, but if you (or anyone else) find the solution it would be nice to know.

I am using the code from tutorial and if member is logged in fields can't be changed because of the code
<?php echo $readonl; ?>
since under this code we have:
<?php
global $my, $mosConfig_live_site;
// first we check if the user is logged
// if so, then we fill out some fields and set them to read only
$readonl = $in = $out = "";
if ( $my->id ) {
  $out=" SELECTED";
  $readonl=" readonly='readonly'";
} else {
  $in=" SELECTED";
}
?>


Do you might know how can I check if field is empty (if user hasn't wrote anything yet on custom field) then field is NOT read-only, but if it's already filed out then it is read-only. I use most of fields which are required at registration but I also have a few which are not, and on the form field is empty and it is read only, but it would be nice to have open field if it's empty just in case if member decides to write something there but he doesn't like to have that info in profile.

I am trying a bit with the code like:
<label for="zip">Zip: </label>
<input type="text" name="zipcode" id="zipcode" tabindex="512" value="{cb_zip}"
<?php 
if ( value=="" ) { 
  echo "";
} else { 
  echo $readonl; 
} 
?> /> <br />
But that doesn't work, but it can't be far from this code right?πŸ™‚
GreyHead 02 Jun, 2008
Hi ExSpiit,

You can try this
<?php
$readonly = "readonly='readonly'" 
$read['zipcode'] = "";
$value = '{zipcode}';
if ( $value ) {
  $read['zipcode'] = $readonly;
}
?>
<label for="zipcode">Zip: </label> 
<input type="text" name="zipcode" id="zipcode" tabindex="512" value="{cb_zip}" <?php echo $read['zipcode']; ?> /> <br />
Not tested and I'm not certain that it will work - it depends on whether {zipcode} is substituted before the php is interpreted - from memory I think it is.

I've used an array for the 'read' variable as in practice I'd run through all the form field in a foreach loop before writing any html.

Bob
ExSpiit 02 Jun, 2008
Works great, I just changed the code to:

if ( $value ) { 
  $read['zipcode'] = 'readonly'; 
} 


Thanks GreyHead B)
GreyHead 02 Jun, 2008
Hi ExSpiit,

Why the shorter version? The specification is

readonly="readonly"

If you only have 'readonly' it may not work in some browsers.

Bob
ExSpiit 02 Jun, 2008
When I tested before there was some problem, that's why I changed to that, but I just tried again with your version and it works, so I changed it back to "$readonly;" now. Thanks.
bawet 26 Jun, 2008

. . . buggy code from earlier post deleted . . .

When is use this, my page is blank.. Can u pls help me out? Tnx..πŸ™‚
GreyHead 26 Jun, 2008
Hi bawet,

I can see a couple of typos in this, particularly that there's a < missing before label on line 9

I've corrected the version in my earlier post, please copy that again and try it.

Bob
bawet 26 Jun, 2008

Hi bawet,

I can see a couple of typos in this, particularly that there's a < missing before label on line 9

I've corrected the version in my earlier post, please copy that again and try it.

Bob



I'll try this tomorow.. You will hear from me then..
Tnx in advance..
bawet 26 Jun, 2008
Well i did try it, but i doesn't work.

I just put this code in the Form HTML field right?

<?php 
$readonly = "readonly='readonly'"  
$read['zipcode'] = ""; 
$value = '{zipcode}'; 
if ( $value ) { 
  $read['zipcode'] = $readonly; 
} 
?> 
<label for="zip">Zip: </label>  
<input type="text" name="zipcode" id="zipcode" tabindex="512" value="{cb_zip}" <?php echo $read['zipcode']; ?> /> <br />
GreyHead 26 Jun, 2008
Hi bawet,

Depends what you are trying to do - the spec for this is in post #9054 earlier in this thread.

Bob
bawet 26 Jun, 2008

Hi bawet,

Depends what you are trying to do - the spec for this is in post #9054 earlier in this thread.

Bob



Well, what i want is that my registered users can sent forms without putting their names in the inputboxes..
I would like to use the CB fieldnames.

I did have it to work, but now i don't want to see the value {name} of {email} in the inputboxes when i'm not logged in.

That is the purpose of this code right?

I would like to do it for more then one field and forms...

I hope you can help me out.

Thank you..

ps. My php knowledge is very bad..πŸ™‚
Astrid 30 Jun, 2008
Somebody already found the solution for not showing the cb fieldnames when user is not logged in?
GreyHead 01 Jul, 2008
Hi Astrid,

Check the userid with something like
<?php
if ( $my->id 1= 0 ) {
  //user is logged in, show form
} else {
  // user isn't logged in, show something else
}
?>
Bob
bawet 13 Jul, 2008
Hi Bob,

I use the following code from another post:
<?php 
// Get user-information from Joomla 
$user = &JFactory::getUser(); 
?>

<input type="text" name="username" id="username" value="<?= $user->name; ?>" /> 
<input type="text" name="username" id="username" value="<?= $user->email; ?> " /> 
<input type="text" name="username" id="username" value="<?= $user->id; ?> " /> 


It works great, when you're logged in the fields or filled in, but when you're not logged in, the fields are blank.
That's what i want..

Now, i would like to do this with custom CB fields. How can i do that?

Tnx..

Bart
GreyHead 18 Jul, 2008
Hi Bart,

I don't use CB so I don't have the exact code - you'll need to find the CB table with the information in it, then write an SQL query to look up a particular record and extract the values. That's what getUser() does for you with the Joomla table.

If you can find somewhere in CB that shows the custom fields you can probably copy a code chunk over to do this.

Bob
bawet 18 Jul, 2008
Hi Bob,

I've got something to work..
<?php $user = &JFactory::getUser(); ?>
<input name="name" id="name" type="text" 
  value="<?php if ($user->id > 0) echo $user->name ; ?>"/>
<input name="city" id="city" type="text" 
  value="<?php if ($user->id > 0) echo '{city}' ; ?>" />
<input name="phone" id="phone" type="text" 
  value="<?php if ($user->id > 0) echo '{phone}' ; ?>" />
It works great! '{phone}' is a CB field, $user->name is a Joomla user field...

Bart
GreyHead 18 Jul, 2008
Hi Bart,

Excellent, looks good to me.

Bob
Astrid 22 Jul, 2008
Hi Bart,
Thx. Works perfect!
bman 20 Apr, 2009
How would one then email these custom fields?

I have successfully created a form which pulls certain custom fields from community builder into itself. I see them just fine on the screen. The users do not edit the fields in anyway and can only enter some other information we're asking them for. We're pulling the CB custom fields and trying to populate the email with some of their usual info such as name, address, city, state, zip and about 12 other custom fields so they don't have to type all that info again. This all works fine.

The problem is that when we email the form to us we see the NEW questions and answers we've added on the email, but do not see the community builder custom fields. We see them before clicking submit just fine, they just dont show up on the email.

In the 'Form Code' --> 'Form HTML' I have listed the fields as follows:

{custom1} {custom2} etc etc and thats exactly how they show up on the email that is sent to us!

Any hints/tips?

Thanks in advance.
GreyHead 20 Apr, 2009
Hi bman,

Yes that's good - except that I missed the 'type' from the example there
<input name='phone' type='hidden' value='{phone}' />

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