External Forms!!
Permalink
Hi. Going out on a limb here as the developer forum has not been much help. Long and the short of it, I have website running v8.3.1 with an external form. I have followed the developer information but every time I try and submit a form, the website produces a 404 error.
Anyone had this and resolved it?
Anyone had this and resolved it?
Did this get resolved?
I have the same issue, it is likely the controller is not firing because it cannot be found.
The test_form.php does work, but any custom form does not. I have been struggling with this issue for 6 months and getting very little in the way of answers unfortunately.
The form template should be in 'application/blocks/external_form/form'.
The controller according to the docs should be 'application/blocks/external_form/form/controller'.
Both files should have identical filenames. Whatever the action parameter is with in the <form> element, i.e. <?=$view->action('submit')?> should be reflected within the controller file like so public function action_submit( $bID = false ) { ...code... }.
However, having the controller file in the application directory results in a redeclaration of class error regardless of what the class is named, C5 says it exists already. Moving the controller file inside the concrete directory actually works on a local copy of the website. However, this does not work on the live website, it still produces a 404 error.
The directory structure is identical between local and live, only the page ID is different due to each copy of the website using a different database. Swapping out the form block to use the test_form.php template works on both websites.
Controller file
form template file
I have the same issue, it is likely the controller is not firing because it cannot be found.
The test_form.php does work, but any custom form does not. I have been struggling with this issue for 6 months and getting very little in the way of answers unfortunately.
The form template should be in 'application/blocks/external_form/form'.
The controller according to the docs should be 'application/blocks/external_form/form/controller'.
Both files should have identical filenames. Whatever the action parameter is with in the <form> element, i.e. <?=$view->action('submit')?> should be reflected within the controller file like so public function action_submit( $bID = false ) { ...code... }.
However, having the controller file in the application directory results in a redeclaration of class error regardless of what the class is named, C5 says it exists already. Moving the controller file inside the concrete directory actually works on a local copy of the website. However, this does not work on the live website, it still produces a 404 error.
The directory structure is identical between local and live, only the page ID is different due to each copy of the website using a different database. Swapping out the form block to use the test_form.php template works on both websites.
Controller file
<?php namespace Concrete\Block\ExternalForm\Form\Controller; use Concrete\Core\Controller\AbstractController; use Concrete\Core\Page\Controller\PageController; use Loader; use Core; class CustomContactForm extends AbstractController { public function action_submit( $bID = false ) { ...code $this->set( 'response', t( 'Thanks!' ) ); return true; } public function view() { $this->set( 'message', t( '' ) ); } }
Viewing 15 lines of 16 lines. View entire code block.
form template file
<?php $form = Loader::helper( 'form' ); defined( 'C5_EXECUTE' ) or die( 'Access Denied.' ); $cpage = Page::getCurrentPage(); $currentpage = ( $cpage->getCollectionID() ); ?> <?php if( $message ) : ?><p style="font-weight: bold; font-size: 2em;"><?php echo $message; ?></p><?php endif; ?> <?php if( $response !== 'received' ) : ?> <form method="post" action="<?=$view->action('submit')?>"> ...fields... <input type="submit" name="submit" value="submit" class="btn btn-primary" /> </form> <?php endif; ?>
Check your namespace in the controller also. It was originally set to Concrete, I changed it to Application and moved the controller file to 'application/blocks/external_form/form/controller'. This now works correctly across all copies of the website.
I found a similiar issue on the C5 GitHub issues:https://github.com/concrete5/concrete5/issues/2116...
Hope that helps.
namespace Application\Block\ExternalForm\Form\Controller;
I found a similiar issue on the C5 GitHub issues:https://github.com/concrete5/concrete5/issues/2116...
Hope that helps.
One other piece that I found is that the external form cannot be in a stack. The block has to be a page default or added to the page as its own block otherwise you will receive a 404 when submitting.
Share the code if you want, maybe there's an easy solution.