Forums

Auto fill - REally! I'm sooo close please help!

sitebuildernow 02 Jan, 2012
Hi, I have read and re-read all of the posts regarding the auto fill "get user" information here in the forums but I am still having troubles because I want to be able to get the info into the form fields not just to display. I also have the chronoforms cook book and still need help.

So here is my form: http://www.asnwonline.com/index.php?option=com_chronocontact&Itemid=38

What I want to do is have the fields that don't change such as First Name, contact info and billing info from order to order to auto fill for logged in users. This information is found in the jos_comprofiler_fields db.

I have figured out how to get user data and display it just as text at the top of the page but not how to get it to autofill into the form fields so it can be edited for any given order. Any help is GREATLY appreciated.

So basically I want the form to just be blank and ready to use if the user is not logged in but if they are logged in many of these fields will be filled in for them. Make sense?

I am using Joomla! 1.5.23 and ChronoContact V 3.2 along with Community Builder.
Harmony
sitebuildernow 04 Jan, 2012
:( ok, I have made my form connect to the juser database it appears and I can auto fill "some" fields but I need it to connect to the database with all of my community builder fields in it so I can autofill all of the fields that a user will have stored. So, after spending the last 8 hours on this I could really use some help to take it to the next level. All I need to know is how to make the form look up the data for the logged in user from the jos_comprofiler_fields table instead of the default joomla user table.

Here is the code (just part of the form but shows my syntax etc) - I can autofill the name but not the first name (which is firstname in the table I'm trying to call from). I even get the username to display properly "you are logged in as" I can get email but not a phone number... I am sure it's because my form is not looking up the data in the right place:
<?php
global $mainframe;
$database =& JFactory::getDBO();
$my = JFactory::getUser();
$query = "SELECT * FROM #jos_comprofiler_fields WHERE user_id = '".$my->id."'";
$database->setQuery( $query );
?>
<div>Your are logged in as <?php echo $my->username; ?>"</div>

<input type='hidden' name='jobid' value='' />
<input id="subject" name="subject" type="hidden"/>
<div class="form_item">
<div class="form_element cf_heading">
<h1 class="cf_text">Requester's Details</h1>
</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">First Name*</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="Please provide requester first name" id="text_1" name="rfname" value="<?php echo $my->name; ?>" type="text" />
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">First Name* :: Who can we contact with questions about this request?</div>
</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Last Name*</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="Please provide requester last name" id="text_2" name="rlname" value="<?php echo $my->lastname; ?>" type="text" />
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Last Name* :: Who may we contact with questions about this request?</div>
</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Company or Organization*</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="Please provide the requester company or organization name. If an individual just type individual" id="text_3" name="rcompany" value="<?php echo $my->company; ?>" type="text" />
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Company or Organization* :: Please provide the requester company or organization name. If an individual just type individua</div>
</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Email*</label>
<input class="cf_inputbox required validate-email" maxlength="150" size="30" title="Please provide the requester email" id="text_4" name="remail" value="<?php echo $my->email; ?>" type="text" />
<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Email* :: Please provide an email address to confirm we recieved this request and contact the requester with any questions.</div>
</div>
<div class="cfclear"> </div>
</div>
sitebuildernow 04 Jan, 2012
Since I had to spend many many hours figuring this out by reading through many many many posts on this forum and I only figured it out by guessing and trial and error I thought I would post my solution:

Need - I had a great form but wanted to auto fill as much as I could if a user was logged in so they did not have to type in the data. This is an online appointment request type form so we get many repeat customers.

I am using Joomla! 1.5.20 and ChronoForms V3.2.

It was "easy" to get data from the standard JUser table but I could not figure out how to get data that was stored in my community builder comprofiler table. I am not a php programmer - but I found a variety of forum posts that had pieces of what I thought I needed and I finally put this code together for the call to get the user data and then added the value= statements for each field - I guess I had to do a query of the table and then tell the form how to interpret the results and put the data in the right fields - again, I don't know the terminology - I just know I got it to work! Note that I chose the 'cb' naming convention - I guess this tells the form to look in this database (nicknamed cb) instead of the JUser table for the values... Would love to have my solution re-written by someone that knows what I'm talking about so others could use it!:

<?php
    global $mainframe;
$database =& JFactory::getDBO();
$my = JFactory::getUser();
    $query = "SELECT *"
       . "\n FROM #__comprofiler"
       . "\n WHERE user_id = '$my->id'";
    $database->setQuery( $query );
    $cb = $database->loadObjectList();
    $cb = $cb[0];
    ?>
<div class="form_element cf_heading">Your are logged in as <?php echo $my->username; ?></div>

<input type='hidden' name='jobid' value='' />
<input id="subject" name="subject" type="hidden"/>
<div class="form_item">
  <div class="form_element cf_heading">
    <h1 class="cf_text">Requester's Details</h1>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">First Name*</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="Please provide requester first name" id="text_1" name="rfname" value="<?php echo $cb->firstname; ?>" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">First Name* :: Who can we contact with questions about this request?</div>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Last Name*</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="Please provide requester last name" id="text_2" name="rlname" value="<?php echo $cb->lastname; ?>" type="text" />
  <a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
				<div class="tooltipdiv">Last Name* :: Who may we contact with questions about this request?</div>
  </div>
  <div class="cfclear"> </div>
</div>
GreyHead 04 Jan, 2012
Hi sitebuildernow ,

Thanks for posting this - I'm sure it will be useful. Neither Max or I is a CB user so we find these requests difficult to answer.

There is very little in your code that I would do differently, mostly cosmetic stuff.

Bob

PS it's the FROM #__comprofiler that identifies the table - you could have used anything in place of $cb, $xxyyz would work.
sitebuildernow 04 Jan, 2012

Hi sitebuildernow ,

Thanks for posting this - I'm sure it will be useful. Neither Max or I is a CB user so we find these requests difficult to answer.

There is very little in your code that I would do differently, mostly cosmetic stuff.

Bob

PS it's the FROM #__comprofiler that identifies the table - you could have used anything in place of $cb, $xxyyz would work.



Hi GreyHead - I understand that you guys simply can't answer every question. I am open to any cosmetics code cleanup you recommend!

Harmony
GreyHead 08 Jan, 2012
Hi Harmony,

These really are tiny changes in the MySQL query, the biggest is to only request a single record. I've also removed the line breaks from the query - they are only helpful to human readers
$database =& JFactory::getDBO();
$my = JFactory::getUser();
$query = "SELECT *
  FROM `#__comprofiler`
  WHERE `user_id` = '{$my->id}';
";
$database->setQuery( $query );
$cb = $database->loadObject();
?>

Bob
fkaram65 10 Feb, 2012
HI guys,

Great topic. I am trying to do the same thing and this code seems to work great on pulling out the field date from the jml_users table. However, when I try to use it on the jml_comprofiler table and attach it to a field in that table it does not work?

Any thoughts?
sitebuildernow 10 Feb, 2012
Hi fkaram65 - I "think" you need to leave off the jml part - only put in the _comprofiler part... but I'm only a hacker and not a programmer at all!
Harmony
GreyHead 11 Feb, 2012
Hi fkaram65,

The jml_ prefix is probably needed but because prefixes vary I use the Joomla! default prefix of #__ in examples here. Joomla! will replace that with the specific prefix for your site.

My memory is that CB uses a complex table sturcture for some fields. You probably need to test the MySQL using PHPMy Admin to make sure that it works correctly.

Bob
mabeach 13 Feb, 2012
Thanks for bring this up. I am also doing the same thing.

I use a bit of php to get the user name and login names. Then I add this to the value="" of the input option I want.


Gets Name:

value="<?php $user =& JFactory::getUser(); $user_id = $user->get('name'); echo $user_id; ?>"


Gets e-Mail:
value="<?php $user =& JFactory::getUser(); $user_id = $user->get('email'); echo $user_id; ?>"




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