Include a custom form on a Concrete5 page

Permalink
I want to include a custom form that I created inside a Concrete5 page on a site. I have downloaded the PHP Code Block add-on (https://www.concrete5.org/marketplace/addons/php-code-block), and it's working. However, I'm having trouble with an included file, and I'm not sure what syntax is allowed within Concrete5. This doesn't work: <?php include('cform.php'); ?>. Even though it's in the same folder as all of my C5 Theme files, it can't find it, so I'm guessing I need to specify a path.

An unexpected error occurred.
include(cform.php): failed to open stream: No such file or directory

This works in a normal PHP page, but not within a Concrete5 page: <?
include(__DIR__."/cform.php");
?>

So, my question is, what is the syntax that I have to use to specify a path, so this included file can be found?

Can anyone point me in the right direction?

Thank you.

ssailer
 
mnakalay replied on at Permalink Reply
mnakalay
Can I ask why you're doing it this way instead of using one the 2 core form blocks included with Concrete5? That might not be necessary.
ssailer replied on at Permalink Reply
ssailer
I want to be able to specify where I put the form fields. I see Form (Form) and Legacy Form (Other). Is this what you are referring to? The Legacy Form is okay ... just doesn't give enough formatting options.
mnakalay replied on at Permalink Reply
mnakalay
Those blocks don't come with formatting options mostly because Concrete5 includes a very flexible and powerful templating engine. So technically you would create a template for the form block and you would make it look any way you want.
An added benefit is that you would have all your form submissions listed nicely in your dashboard.

Making a template is not that complicated but you have to know some (a little) PHP.
brutalnv replied on at Permalink Reply
brutalnv
You can use external forms with an arbitrary fieldset and custom controller:

https://documentation.concrete5.org/editors/in-page-editing/block-ar...

Take a look at the /concrete/blocks/external_form/form to see an external form example code.
ssailer replied on at Permalink Reply
ssailer
brutalnv, just to be clear, I can create ANY form as long as it resides in this folder: concrete\blocks\external_form\form? What about if the form has includes?

Thanks!
linuxoid replied on at Permalink Reply
linuxoid
Creating your own form block is very simple in Concrete5. Download any free addon from the market place and change the folder names for your own, change the namespaces in controllers (in accordance with the C5 convention), replace code in view.php to show form fields, in controller.php to process the form, in view.js to perform javascript processing, in form.php to save various variables in the database, in the db.xml to define what will be saved.

Take the Login addon as the basis, for example:
https://www.concrete5.org/marketplace/addons/login-block...