Including a PHP Source File in a Code Auto Action Box

3 years 3 months ago #322423 by bascherz
For the past week I have been "cleaning up" my new site since everything seemed to be working pretty well. One thing I did was move the PHP code snippets from every Auto Action into individual files that I include instead of having the code in the Auto Action action box directly. Well, this caused an interesting problem I've been scratching my head over for almost an entire week.

First, all my include files have the customary <?php ?> tags in them. I do this for a reason; so that I know I am editing a PHP source file. However, I suspect (have not confirmed) that if these tags are in the file that somehow CB substitution doesn't work on the included code. Why do I suspect that? Because I geocode every address entered during registration using Google Maps API. The string I pass to it is formed like "[cb_street]+[cb_city]+[cb_state]+[cb_zip]". This had been working for 2 months when the very small code snippet was in the Auto Actions box. But once I moved it to an include file (with those php tags), it geocoded every single address as "26 Strathmoor Dr, Sherwood Park, AB T8H 2B6, Canada". This is the result you get when you geocode that string without the field substitutions. Give it a try and see for yourself.

I did not put two and two together for almost a week, convinced that somehow something was intercepting the SSL queries I was doing.

So the question is, should these include files not have the php tags? Is that what causes this? Should the files just contain bare PHP code without these context tags? Curious minds want to know!

Bruce

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

3 years 3 months ago #322428 by krileon
Substitutions are ran before the PHP is ran. This means any substitutions inside of your PHP file will never process. You'd need to set some variables before your include that your include could then use. Do not use <?php ?> tags in a Code action as it's already treated as PHP. Example as follows of what you'd need to do.

$userAddress = '[cb_street]+[cb_city]+[cb_state]+[cb_zip]';

include( 'FILE_PATH_HERE' );

Then in your included PHP file use $userAddress. Your PHP file should also have access to the predefined variables of the code action like $user and $variables, but again you will not have access to substitutions in your include file.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

3 years 3 months ago #322434 by bascherz
Good to know. Thanks.

______________________
Bruce S - Vienna, VA

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.607 seconds

Facebook Twitter LinkedIn