Page not found error once submit form in addons contact_directory using concrete5?

494 views Asked by At

I have purchased add-ons module contact_directory using concrete5, now I have need to customize on my requirement.

so I have need to changed file packages\contact_directory\blocks\contact_directory\view.php, I have created test.php file in same directory where my view.php file, so my form tag is url('contact_directory/test')?>">

so please tell me where it's wrong?

1

There are 1 answers

0
Jordan Lev On

Concrete5 utilizes a loose MVC architecture for blocks. What this means is that unlike "plain old" php sites where you have a file that gets run when a certain URL is visited, your block's controller is always called instead. But you can have different functions in the controller that respond to different url's, and in the C5 world these are called actions.

So in your block's view.php file, change your form tag to this:

<form method="post" action="<?php echo $this->action('test'); ?>">

Then in the controller.php file, make a new public function that has the name "action_" followed by what you passed into the form tag. In your example, that would be:

public function action_test() {
    //do stuff here
}

Now you're going to run into an issue because Concrete5 blocks always render the "view.php" template (there is no easy way to tell it to use a "test.php" file instead, for example). The easiest solution here is to combine two templates into your view.php file with an "if" statement. For example:

<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>

<?php if ($controller->getTask() == 'test'): ?>

    <!-- Put all of the code from your test.php file here -->

<?php else: ?>

    <!-- Put all the code from your view.php file here -->

<?php endif; ?>

One thing to note -- if your block gets placed in the Page Defaults or in a Global Area (or Stack), then it's possible that the form action won't submit to the right place. I'm not sure about this though -- this was a problem I ran into back in version 5.4.2, but it may have been fixed since then.

PS - If you want to look at some sample code that utilizes this form handling stuff in C5 blocks, download my free Email List Signup addon ( http://www.concrete5.org/marketplace/addons/email-list-signup ).