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

pvernaglia
View Replies: View Best Answer
jordanlev replied on at Permalink Reply
jordanlev
If it's an external form that posts to an external site, then the only way you could email someone is by changing the form to post to your site, sending the email, then posting it to the other site from within your code (e.g. using "curl"). Or you could try some javascript on the form that posts to an ajax method on your site which sends the email. Either way, there is some complex coding involved.

Or is this not what you mean by "external form"?

-Jordan
pvernaglia replied on at Permalink Reply
pvernaglia
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
moth replied on at Permalink Best Answer Reply
moth
If you're starting with the example external form block included in C5, try something like this;

<?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


More info here:http://www.concrete5.org/documentation/developers/helpers/mail...
pvernaglia replied on at Permalink Reply
pvernaglia
Thanks, that's got me going in the right direction!
intellib replied on at Permalink Reply
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
moth replied on at Permalink Reply
moth
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;
}
?>
intellib replied on at Permalink Reply
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?
jolson replied on at Permalink Reply
jolson
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 );
}
}