POST Variables and tools files

Permalink
hi, I hope somebody will be able to help me out

I want to pass data from a form to a php script within the /tools directory.

I don't want to create a single page I just want to POST some form variables from a page outside of Concrete5 for example:

http://www.mysite.com/myform to
http://www.mysite.com/index.php/tools/myfile.php...

then my code can do what it needs to do with the POSTed variables.

However, when I submit the form the POSTed variables are stripped out along the way somewhere.

for example if I have in my form a field named 'test'.

in /tools/myfile.php I add echo $_POST['test'] - I get nothing.

What am I missing here? I want to be able to leverage the API but cannot get the POST to work. If I submit the form directly to the tools file without going via index.php the variables are there.

I must be doing something very basic wrong...

 
guythomas replied on at Permalink Reply
guythomas
There is a special method that generates a tool file url. You may check into that to ensure you are actually getting to the tool file. If you put an echo statment in there, is it being executed?
monkeywrench replied on at Permalink Reply
maybe that's the problem then.

I want to be able to access the tool file from a pahe that is outside the Concrete5 website - that being the case I won't have access to the method.

I tried a GET and that seems to work ok - I guess because of the way the GET mechanism works...

Is that the case then - you cannot POST from a file outside of Concrete5 to a tools file to run a routine?
jordanlev replied on at Permalink Reply
jordanlev
You can post to a tools page from outside of concrete5 -- you just need to figure out what its special URL is (run getToolsURL() on it once from within c5 to see what it is, then use that outputted path in your external page).

How exactly are you sending the form data? Are you using the jquery Ajax form library?
monkeywrench replied on at Permalink Reply
Hi Jordan - thank you very much for that. I'm actually just doing a straight html post from a form but really it could be done any way...
jordanlev replied on at Permalink Reply
jordanlev
I just tested this out and the POST data is in fact sent to the tools file. The URL format is:
http://yoursite.com/index.php/tools/yourfilenamewithoutextension

Note that there is no ".php" at the end of the filename (so if your tools file is called "myawesomefile.php", the tools URL is "http://yoursite.com/index.php/tools/myawesomefile").

And note that I tested this in the site's top-level "tools" directory -- it might need a different URL if you're doing this from within a package.
monkeywrench replied on at Permalink Reply
not sure what I'm doing wrong but there is definitely nothing in the post. I'll redo everything from the top again in case there is some silly thing I've missed...
jordanlev replied on at Permalink Reply
jordanlev
I think if you provide the following 3 things I can provide a more helpful answer:
* Post the actual tools file you're using (ZIP it up so the forum will let it be posted)
* Say *exactly* what directory you have it in on your server
* Post the form html you have on the external site.
RadiantWeb replied on at Permalink Reply
RadiantWeb
you would want to use $_REQUEST in your tools file, not $_POST

ChadStrat
jordanlev replied on at Permalink Reply
jordanlev
Can you explain this more Chad? I don't know of a situation where POST'ed data would be in $_REQUEST but not $_POST (unless C5 is manually removing them from $_POST, but I don't think that's happening because I often use $_POST in my tools files without any problems).
RadiantWeb replied on at Permalink Reply
RadiantWeb
I just know that I have several API tools file's working with $_REQUEST from external AJAX forms. I have never gotten $_POST to work. ever.

ChadStrat
jordanlev replied on at Permalink Reply
jordanlev
That's so weird. But a great tip to know, thanks for sharing.
mkly replied on at Permalink Reply
mkly
Yup. Same here.
mkly replied on at Permalink Best Answer Reply
mkly
Ok. I'm just braindead. I always use getJSON() and really didn't think it through. I just did a test with $.post and I got post data. This was a block.
RadiantWeb replied on at Permalink Reply
RadiantWeb
I always use .get as well. And then $_REQUEST seems to work nicely from a tools file standpoint just because it's more flexible.

ChadStrat
jordanlev replied on at Permalink Reply
jordanlev
Okay, I think I see the issue...
Using $.get or method="get" in your form will send the data to $_GET, not $_POST.
But you're absolutely right that $_REQUEST will always work for everything ($_GET and $_POST and even $_COOKIE), so might as well keep doing what you're doing.
RadiantWeb replied on at Permalink Reply
RadiantWeb
Also, $_REQUEST includes $_POST.

I dont' know the inner workings of why, I just know that $_POST sucks. lol

C
JohntheFish replied on at Permalink Reply
JohntheFish
Ajax lessons, Concrete Bricks and Concrete Paving all use $_POST successfully in tools files. However, the ajax all of these do is trivial and I have used $_REQUEST in other cases purely for flexibility in how I call the tool.

[edit] Just an afterthought, I think I used the jQuery load() request for all these. Maybe that is the trick.