ashoks / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
GNU General Public License v3.0
0 stars 0 forks source link

relative address unknown when creating a Joomla! component #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, LOVE THIS LIBRARY !!!   You guys are awesome.

I'm not a red-hot programmer, so maybe I'm doing something stupid, in which
case I apologize in advance.

Trying to create a Joomla! component.  

If i set the relative includesRelativePath" correctly (ie: /includes), then
i don't get the error message.  but the forms don't work - specifically the
TinyMCE and CKEditor don't initialize.

Here's what i had to do to get the code working.

"includesRelativePath" => JURI::base( true )
."/components/com_agenda/php-form-builder-class/includes"

Trouble is that now the 'Invalid Includes Directory' error message pops up,
even though the example scripts work perfect when I embed them in my code.  

My guess is that the FILE_EXISTS() and IS_DIR() functions are relative to
the start of Joomla!.

I'm running version 1.0.2 under Ubuntu.

Original issue reported on code.google.com by tom.bere...@gmail.com on 12 Apr 2010 at 2:13

GoogleCodeExporter commented 8 years ago
Hi,

Can you please edit the class to print out the value of 
$this->includesRelativePath

Just modify the class and edit at

    public function elementsToString($includeTableTags = true)
    {

and put under it

die($this->includesRelativePath);

And post the output here, thanks!

Original comment by moncojhr@gmail.com on 12 Apr 2010 at 2:39

GoogleCodeExporter commented 8 years ago

/community2/components/com_agenda/php-form-builder-class/includes

'community2' is the root of my joomla installation. 'com_agenda' is the 
component i
am building.   the full path is something like /home/tom/HTML/community2/...

Original comment by tom.bere...@gmail.com on 12 Apr 2010 at 2:56

GoogleCodeExporter commented 8 years ago
Hi thanks, for your report, this is caused because you are using a absolute path
instead of a relative path.

Perhaps the should be changed to includesPath and have a function to check if 
it is a
relative path or a absolute path to make the decision if the path is set 
incorrectly.

For now you can comment out the two lines in the class while we fix it:

if(empty($this->includesRelativePath) || 
!file_exists($this->includesRelativePath) ||
!is_dir($this->includesRelativePath))
            $str .= "\n\t" . '<script type="text/javascript">alert("php-form-builder-class
Configuration Error: Invalid includes Directory Path\n\nUse the 
includesRelativePath
form attribute to identify the location of the inclues directory included 
within the
php-form-builder-class folder.");</script>';

to stop the warning.

Original comment by moncojhr@gmail.com on 12 Apr 2010 at 3:00

GoogleCodeExporter commented 8 years ago
Here is a change to the logic so it checks absolute paths and relative paths:

            if(empty($this->includesRelativePath) || !is_dir($this->includesRelativePath)
                        && (!file_exists($this->includesRelativePath) &&

!file_exists($_SERVER['DOCUMENT_ROOT'].$this->includesRelativePath) ))
            $str .= "\n\t" . '<script type="text/javascript">alert("php-form-builder-class
Configuration Error: Invalid includes Directory Path\n\nUse the 
includesRelativePath
form attribute to identify the location of the inclues directory included 
within the
php-form-builder-class folder.");</script>';

Original comment by moncojhr@gmail.com on 12 Apr 2010 at 3:28

GoogleCodeExporter commented 8 years ago

Original comment by moncojhr@gmail.com on 12 Apr 2010 at 5:15

GoogleCodeExporter commented 8 years ago
Tom,

Thanks for your support of this project.

The includes directory contains both javascript and php components that are 
used by the class.  An absolute 
path in a javascript environment differs from that in a php environment because 
the initial slash is interpreted 
differently.  In javascript, the slash begins at the document root while in php 
the slash represents the root 
directory of the web server.  Because of this difference, a relative path is 
used to identify the includes 
directory.  This way, both javascript and php and share the same path.

Just because the javascript alert error message is suppressed doesn't 
necessarily mean that the includes 
directory is correctly identified for both javascript and php.

- Andrew

Original comment by ajporterfield@gmail.com on 12 Apr 2010 at 1:55

GoogleCodeExporter commented 8 years ago
Thanks Andrew.

you are right, i've changed to a relative address. but the real problem is 
still there.

here's the relative address that works (ie: loads the javascripts for TinyMCE, 
etc.)

incudesRelativePath" => "components/com_agenda/php-form-builder-class/includes"

but it doesn't make your safety-check happy (ie: it pops up the message "invalid
Includes Directory Path").  the relative path that makes the error go away is 
simply:    

incudesRelativePath" => "includes"

but that doesn't load the javascripts (ie: doesn't work).

i commented out the error message.

Original comment by tom.bere...@gmail.com on 12 Apr 2010 at 3:21

GoogleCodeExporter commented 8 years ago
Should have thought of that...

you can have an absolute path and it will work perfectly fine... except for 
when the
class does

require_once($form->includesRelativePath . "/recaptchalib.php");

So you would need to change that... you could check if the path starts with / 
and if
it does slap on $_SERVER['DOCUMENT_ROOT'] ...

It becomes a problem specifying the relative path if you are messing around with
mod_rewrite or including forms from random directories.

So I think its necassary to get absolute paths working.

Andrew, do you want me to go in and make all the php side stuff work with 
absolute
paths + use my patch for the javascript error check?

Cheers,
moncojhr

Original comment by moncojhr@gmail.com on 12 Apr 2010 at 5:30

GoogleCodeExporter commented 8 years ago
moncojhr,

I think a good approach would be to...

1.  Change the includesRelativePath attribute to includesPath to remove any 
confusion on if the path is relative 
or absolute.
2.  Allow both relative and absolute paths to be handled correctly.  If the 
includesPath attribute does not begin 
with a slash, it is handled as it is currently in version 1.0.2.  If there is 
an initial slash in the includesPath 
attribute, then we need to determine if the user is beginning the path from the 
server root or document root.  
This could turn out to be easier said than done, but it's worth a shot.  One 
way to implement would be to put 
all of these conditional checks at the start of the elementToString() function, 
which is where the current js alert 
in question is.  Then two private form attributes (jsIncludesPath and 
phpIncludesPath) could be set for future 
use in the class.  This approach eliminates the need to check the path multiple 
times throughout the form 
building process.
3.  Leave the default value as it is currently in version 1.0.2 which 
identifies the path as relative.  For most 
developers using this class, the default value will prevent them from having to 
define this attribute when 
building forms.  If we switch the default value to assume an absolute path, my 
fear is that more people will 
have to include with attribute in each of the forms they build.

Original comment by ajporterfield@gmail.com on 12 Apr 2010 at 8:42

GoogleCodeExporter commented 8 years ago
Tom,

Unfortunately, I do not have experience using Jumla! which makes it a challenge 
for me to provide you with setup 
advice.  Adding support for absolute paths may or may not remedy your issue.  
One thing you may try is to create 
a symbolic link of the php-form-builder-class directory to satisfy the path 
discrepancies.

- Andrew

Original comment by ajporterfield@gmail.com on 12 Apr 2010 at 8:49

GoogleCodeExporter commented 8 years ago
Hi Tom, in the SVN version i've added a patch so you can use absolute and 
relative
paths now.

Can you please get the SVN version and test it?

It should work when you use "includesPath" => JURI::base( true )
."/components/com_agenda/php-form-builder-class/includes"

Note that the variable name includesRelativePath is deprecated in favour of
includesPath now.

Original comment by moncojhr@gmail.com on 14 Apr 2010 at 5:02

GoogleCodeExporter commented 8 years ago
includesPath worked like a charm.   :)

includesRelativePath no longer gives an error when i give it the
/component/com_agenda/...  string, either in absolute or relative (the old 
behavior
was that it worked but gave an erroneous error).  

includesRelativePath behaves the same as before when i give it 'includes' (ie:
doesn't complain but doesn't work).  

it's all good.

thank you.

Original comment by tom.bere...@gmail.com on 14 Apr 2010 at 1:33

GoogleCodeExporter commented 8 years ago
Hi, just to let you know includesPath works with absolute and relative paths, 
but in
your circumstance you dont know where the form is going to load so you cant use 
a
relative path.

includesRelativePath is just set to includesPath for the moment so it wont break
anyone's form and will eventually be removed.

Thanks for testing!

Original comment by moncojhr@gmail.com on 15 Apr 2010 at 2:58

GoogleCodeExporter commented 8 years ago
hi , i just uploaded the pfbc and the same problem is being display throw fire 
bug in "CKEDITOR is not defined" what should i do :(

Original comment by josianei...@gmail.com on 27 Jan 2012 at 9:53