External Form controller
Permalink 3 users found helpful
Hi, I have an external form that just needs to be emailed to someone. Does anyone have a sample of a controller that will do that?
Thanks
Thanks
I'm using the external form block, I have the form all set but I'm not sure on how to parse the form data to send it with the mail helper through the controller
If you're starting with the example external form block included in C5, try something like this;
More info here:http://www.concrete5.org/documentation/developers/helpers/mail...
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class TestFormExternalFormBlockController extends BlockController { public function action_test_search() { $val = Loader::helper('validation/form'); $mh = Loader::helper('mail'); // Validate $val->setData($this->post()); $val->addRequiredEmail('email', 'Make sure you have entered a valid email address.'); // You get get form data like this $name = $this->post('name'); $company = $this->post('company'); // If no errors if ($val->test()) { // Send Email
Viewing 15 lines of 29 lines. View entire code block.
More info here:http://www.concrete5.org/documentation/developers/helpers/mail...
Thanks, that's got me going in the right direction!
Where would I put the error messages in an other language? Do I have to make an external form with controller for each language? - THX
If it's just a few languages, and you're not worried about the translation of input labels etc, I would put all the error messages in a switch statement, in the same controller.
<? switch ($lang) { case 'en': $val->addRequiredEmail('email', 'Make sure you have entered a valid email address.'); break; case 'fr': $val->addRequiredEmail('email', 'Assurez-vous que vous avez entré une adresse email valide.'); break; default: $val->addRequiredEmail('email', 'Make sure you have entered a valid email address.'); break; } ?>
Thanks.
Now I add three, four forms more to my site, and every with diffrent error messages, where do I put the diffrent languages text to make it more user friendly to change...in a central file, place or offers C5 an other technic?
Now I add three, four forms more to my site, and every with diffrent error messages, where do I put the diffrent languages text to make it more user friendly to change...in a central file, place or offers C5 an other technic?
Instructions for localization are here:http://www.concrete5.org/documentation/developers/system/localizati...
In your external form you may translate the controller response like this:
if ( isset( $response ) ) {
echo t( $response );
}
and errors ...
if ( isset( $errorArray ) )
{
foreach( $errorArray as $ERR )
{
echo t( $ERR );
}
}
In your external form you may translate the controller response like this:
if ( isset( $response ) ) {
echo t( $response );
}
and errors ...
if ( isset( $errorArray ) )
{
foreach( $errorArray as $ERR )
{
echo t( $ERR );
}
}
Or is this not what you mean by "external form"?
-Jordan