Posts: 24
Threads: 7
Joined: Jan 2009
Reputation:
0
No matter how much I try to add a single page form through the api it will not work! I am on the first step of the tutorial asking me to add that php code and I always get the error:
Fatal error: Call to undefined function ft_api_init_form_page()
I have the api installed fine, and the require_once path is correct. Help?
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Hmm... it does *sound* like the require_once() path is incorrect, I must confess. That function is defined in api.php, so if the file is included properly you should never see the error.
Try switching between a relative and absolute path and see if that helps.
- Ben
Posts: 24
Threads: 7
Joined: Jan 2009
Reputation:
0
(May 9th, 2009, 12:57 PM)Ben Wrote: Hmm... it does *sound* like the require_once() path is incorrect, I must confess. That function is defined in api.php, so if the file is included properly you should never see the error.
Try switching between a relative and absolute path and see if that helps.
- Ben
That's what I thought too... but, when I changed the path to something I knew was wrong I got this instead:
"Warning: require_once(/election/database/global/api/api.php) [function.require-once]: failed to open stream: No such file or directory"
So I know the other path was correct (and absolute)
Maybe this will help:
I'm building my website with a CMS called concrete5 and in order to execute code when I website loads it needs to be part of another function. The entire code is here:
PHP Code: <?php class CandidatesRegistrationController extends Controller { public function on_start() { require_once("http://election.cya-ajc.ca/database/global/api/api.php"); $fields = ft_api_init_form_page("", "test"); $params = array( "submit_button" => "submit", "next_page" => "/success.php", "form_data" => $_POST, "finalize" => true ); ft_api_process_form($params); } } ?>
Any more thoughts?
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Ah! Any time you include() or require() files you need to use server paths, not URLs. If you can't figure out the right absolute path (I've been there!) try a relative one instead - but make sure its relative from the CALLING page, not the file containing the class. If you're calling that class from multiple pages, you'll need to doctor the class like so:
PHP Code: <?php class CandidatesRegistrationController extends Controller { public function on_start() { $curr_folder = dirname(__FILE__); require_once("$curr_folder/../path/to/database/global/api/api.php"); $fields = ft_api_init_form_page("", "test"); $params = array( "submit_button" => "submit", "next_page" => "/success.php", "form_data" => $_POST, "finalize" => true ); ft_api_process_form($params); } } ?>
But you'll need to update the relative path in the require_once() call for your setup. What that new code does is always compute the relative path to the api.php file from the file containing the class - not the original file that includes the class file.
Jeez that sounds confusing. Paths are always a nuisance to figure out... maybe the absolute path is the simplest!
- Ben
Posts: 24
Threads: 7
Joined: Jan 2009
Reputation:
0
May 9th, 2009, 2:39 PM
(This post was last modified: May 9th, 2009, 3:13 PM by stevenheidel.)
Okay now I've got the paths correct. (Checked by my boss as well).
But your script keeps directing the page to error.php, which doesn't exist. Weird?
EDIT:
Oh I see, formtools directs you to this script when there is an error. Unfortunately, the error.php comes up in the same folder as the page itself, not in the formtools directory.
New code:
PHP Code: <?php class CandidatesRegistrationController extends Controller { public function on_start() { $curr_folder = dirname(__FILE__); require_once("$curr_folder/../../database/global/api/api.php"); $fields = ft_api_init_form_page("", "test"); $params = array( "submit_button" => "submit", "next_page" => "success.php", "form_data" => $_POST, "finalize" => true ); ft_api_process_form($params); } } ?>
Posts: 24
Threads: 7
Joined: Jan 2009
Reputation:
0
So I figured out from the folks at concrete5 (which, apart from being incompatible with formtools, is a great CMS) that all included scripts must be converted to libraries, which is impractical.
I simply solved this problem by putting the form in an iframe and all the candidate lists and api stuff in pop-ups, which is fine. It actually makes my site a little more clear. But anyways, thanks for your help, everything is working fine now through my workaround. Sorry about posting in the forum and submitting a bug and sending you an email .
(If you do stumble across a solution though, I'd be curious, but as I said I'm 100% fine with my workaround).
Posts: 2,456
Threads: 39
Joined: Dec 2008
Reputation:
6
Hey Steven,
No worries at all - glad it got solved! And sorry for not responding in the bug tracker or here in the forums earlier. SO little time...
I would be interested in learning more about the way concrete5 requires the code, though. Having them as libraries doesn't seem like an outrageous requirement to me.
Another chap has been looking into creating Form Tools as a Joomla mod. Depending on how that goes, it may shed some light on solutions for other scripts. I'll be sure to post here if and when that ball gets rolling.
All the best -
Ben
|