Block help: Using cURL in blocks
Permalink
I'm trying to create a block that places a form in the page. When submitting this form, I would like to send the data to an external page where the processing happens and sends back a confirmation code.
I would like to do this using cURL so that the data that is sent remains invisible. This is the first time I am trying to create a block. How should I go about doing this? Do I need to enable cURL somewhere in C5 settings?
I would like to do this using cURL so that the data that is sent remains invisible. This is the first time I am trying to create a block. How should I go about doing this? Do I need to enable cURL somewhere in C5 settings?
Hi Jordan
Thanks for that. Yes if you could explain where that goes, that will be awesome. I am just starting out with this, so I am not too familiar with block development at this stage. Your explanation could help other people in the future too.
Also, a reply below yours has suggested to use getContents function. But isn't that only for getting the content from the remote url? My concern is to pass data to the remote page.
Thanks
Thanks for that. Yes if you could explain where that goes, that will be awesome. I am just starting out with this, so I am not too familiar with block development at this stage. Your explanation could help other people in the future too.
Also, a reply below yours has suggested to use getContents function. But isn't that only for getting the content from the remote url? My concern is to pass data to the remote page.
Thanks
Yep. See this post, where I have some sample code for a basic form block:
http://www.concrete5.org/community/forums/customizing_c5/external-f...
As per step 5 in the instructions, put the code you want to run when the form is submitted (your cURL code in this case) into the "action_submit_form" function of the controller.php file.
By the way, I'm assuming you're talking about a form that appears on the front-end of the site for public viewers to fill out -- *not* the "edit" form that an admin user who is managing the site content would see when they edit the page. Let me know if this assumption is incorrect.
HTH
-Jordan
http://www.concrete5.org/community/forums/customizing_c5/external-f...
As per step 5 in the instructions, put the code you want to run when the form is submitted (your cURL code in this case) into the "action_submit_form" function of the controller.php file.
By the way, I'm assuming you're talking about a form that appears on the front-end of the site for public viewers to fill out -- *not* the "edit" form that an admin user who is managing the site content would see when they edit the page. Let me know if this assumption is incorrect.
HTH
-Jordan
Thanks Jordan for your help.
Your replies have been very helpful.
Your replies have been very helpful.
Actually you should use the concrete5 file helpers getContents method.
It has 2 params, the url and the timeout for the operation. So do
Basically the method is checks to see if curl is enabled, and then on the .1% of setups that don't have curl, uses file get contents.
If you aren't using c5 though then use curl.
It has 2 params, the url and the timeout for the operation. So do
$file=loader::helper('file'); $contents=$file->getContents('http://www.url.com');// timout is optional
Basically the method is checks to see if curl is enabled, and then on the .1% of setups that don't have curl, uses file get contents.
If you aren't using c5 though then use curl.
Wow, never knew about that one -- thanks!
How does this work? I tried to put it into a controller PHP file and go the following error:
Class 'Application\Controller\SinglePage\Loader' not found
Class 'Application\Controller\SinglePage\Loader' not found
Try:
Also, if you're doing this on a single page, you'd want to create a controller for it and do a
Which single page are you trying to modify?
$fh = \Core::make("helper/file"); $fh->getContents('YOUR URL HERE');
Also, if you're doing this on a single page, you'd want to create a controller for it and do a
Use File;
Which single page are you trying to modify?
Got it!
This worked :)
This worked :)
Here is some sample CURL code:
This of course assumes you already know how to make the general block and know where to put this code. If you aren't sure about that either, though, let me know and I can try to explain that part as well.