Forums

Show Custom Element from value set in Custom code

ksignorello 19 Jun, 2014
HI!

I have a custom code action set in On Load that gets some date from a DB (that works according to echo and print_r in that action.

I set a variable $title in the code:

<?php
$query="SELECT ExhibitEntries.*,Title,Essay,InitialQty,InitialFee,MaxItemsPerEntry,ExhibitEntries.Exhibitid,InitPrice as CInitPrice,InitQty as CInitQty  , case isnull(DRGMasters.uid) when 1 then 0 else 1 end as isamaster
FROM `ExhibitEntries` join Exhibits on ExhibitEntries.Exhibitid = Exhibits.Exhibitid 
left join ExhibitCoupons on ExhibitCoupons.CouponID = ExhibitEntries.Couponid 
left join DRGMasters on DRGMasters.uid=ExhibitEntries.cf_user_id 
WHERE EntryID =".$form->data['entryid'];
//echo $query;
$db =& JFactory::getDBO();
$db->setQuery($query);
$entryRecord=$db->loadAssoc();
print_r($entryRecord);
$title=$entryRecord['Title'];
echo 'title:'.$title;
?>


Then in a custom element I have this in the code section.

<?php
echo 'title:'.$title;
?>


But the value in $title does not show. is there some setting I have wrong preventing the value from passing form custom code to the element?

I'm sure I'm missing something simple. A little help please.
GreyHead 20 Jun, 2014
Hi ksignorello,

The 'scope' of a PHP variable - the place where it is valid - is very limited to prevent 'pollution'. In ChronoForms the scope is usually limited to a single action. So, $title is not available to other actions.

To get round this ChronoForms uses the $form->data array which is always available and contains all of your form data (and a few other things). You can add a value to this array to make it available.

So use $form->data['title'] = $entryRecord['Title']; in the first action and then either <?php echo $form->data['title']; ?> or just {title} in the Custom Code element.

Bob
ksignorello 20 Jun, 2014
THANKS! that works like a charm. I wasn't sure if you could add to the form data so didn't try that.

I just started working with accordion containers. VERY COOL! BTW I bought the chrono form ebook. But was disappointed to find out it was for version 3.1. Is there a version 4 book coming out?

Thanks for all the great/smart work

Ken
GreyHead 20 Jun, 2014
Hi Ken,

Sorry, no book for CFv4 or v5 planned at present. Packt Publishing commissioned the original v3 one.

There are a couple of hundred FAQs for CFv4 that cover a lot of the ground, and slowly we are adding CFv5 specific info.

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