Page 1 of 1

[solved] FormBuilder 0.7 - Change the destination email

Posted: Thu Jun 02, 2011 5:41 pm
by eoto88
Hi everybody!

I use cmsms 1.9.4.2 "Faanui", with FrontEndUsers 1.12.16, CompanyDirectory 1.8.3 and FormBuilder 0.7.

In my Company Directory Detail Template, I added this line to display the contact form and change the destination value :

Code: Select all

{FormBuilder form='contact' value_fld29=$entry->contact_email}
Sadly isn't working!

Then I tried to change the type of the FromBuilder's field from "Email Results to set Address(es)" to a "Email results based on frontend fields" and add an hidden field where I could put the value of the email.

Same thing, it's not working, and I got this error:

Fatal error: Call to a member function GetHumanReadableValue() on a non-object in modules/FormBuilder/classes/DispositionEmailBasedFrontendFields.class.php on line 56

Using a "Email to User-Supplied Email Address" field type and changing it's value, it's the only way to make it work, but the email can be changed by users!

The reason I need that, is for every Company, I must display the same form but with a different destination.

Thanks, and sorry for my English.

Re: FormBuilder 0.7 - How to change the destination email

Posted: Fri Jun 03, 2011 3:25 pm
by eoto88
Hi everybody!

I found a solution to change the email destination.

I added this line in my CompanyDirectory Details Template :

Code: Select all

{FormBuilder form='contact' value_fld29=$entry->contact_email}
Secondly, I added this UDT (User Defined Tag) :

Code: Select all

$gCms = cmsms();
$form_id = $params['form_id '];

if($form_id = 1) {
  $mail =& $gCms->modules['CMSMailer']['object'];

  if(!empty($params['fld_29'])) {
    $ed = $params['fld_29'];
  } else {
    $ed= '';
  }
  if(!empty($params['your_name'])) {
    $n = $params['your_name'];
  } else {
    $n = '';
  }
  if(!empty($params['your_email_address'])) {
    $e = $params['your_email_address'];
  } else {
    $e = '';
  }
  if(!empty($params['comment'])) {
    $c = $params['comment'];
  } else {
    $c = '';
  }

  $subject = 'Test';
  $body = '<p>Name: ' . $n . '</p><p>Comment: ' . $c . '</p><p>Email: ' . $e . '</p>';
  $mail->AddAddress(  $ed );
  $mail->IsHTML( true );
  $mail->SetBody( $body );
  $mail->SetSubject( $subject );
  $mail->Send();
  $mail->reset();
}
In my form I changed the "Email Results to set Address(es)" for a "Call A User Defined Tag With the Form Results" field where I call the previous UDT.

P.S. The name of the fields could be different! If you have a better solution, I'd like to read it!

Re: FormBuilder 0.7 - How to change the destination email

Posted: Fri Jun 03, 2011 3:49 pm
by calguy1000
$mail =& $gCms->modules['CMSMailer']['object'];
Just a tip:
the $gCms->modules array (among other things) is gone in CMSMS 1.10, so never ever use it, or any other members of the $gCms object directly. Use the accessors that are provided.

i.e: $mail = cms_utils::get_module('CMSMailer');

Re: FormBuilder 0.7 - How to change the destination email

Posted: Fri Jun 03, 2011 4:09 pm
by eoto88
Oh great! Thanks!

Should I change these lines from :

Code: Select all

$comp_dir = $gCms->GetModuleInstance('CompanyDirectory');
$feu = $gCms->GetModuleInstance('FrontEndUsers');
to :

Code: Select all

$comp_dir = cms_utils::get_module('CompanyDirectory');
$feu = cms_utils::get_module('FrontEndUsers');
Because GetModuleInstance use the $gCms object directly!

Thanks again!

Re: FormBuilder 0.7 - How to change the destination email

Posted: Fri Jun 03, 2011 4:18 pm
by calguy1000
I would...

In 1.10 that function in the CmsObject class is deprecated and is just a wrapper around an equivalent function in ModuleOperations.

Re: [solved] FormBuilder 0.7 - Change the destination email

Posted: Mon Oct 15, 2012 2:03 pm
by manuel
Please take a look at this article: http://www.i-do-this.com/blog/88/FormBu ... a-variable
I based it on this thread and added a little extra... :)

Greetings,
Manuel

Re: [solved] FormBuilder 0.7 - Change the destination email

Posted: Sun Feb 17, 2013 4:23 pm
by RHF
    Hi Manuel,
    I have been trying to use the method you describe in your article and have run into a problem with the second and third lines in your code:
    $form_id = $params['form_id'];
    if($form_id = 4) {
    The variable $form_id is not being properly set with the above, and I had to resort to the following to get it:

    Code: Select all

       $actparams = $smarty->get_template_vars('actionparams');
       $form_id = $actparams['form_id'];
    I believe that I must be missing something fundamental here. Surely there is an easier way to get the smarty variable form_id.

    Also, I believe the if statement should be

    Code: Select all

        if($form_id == 4) {
    I posted a question similar to this earlier in this forum but have received no response. I would greatly appreciate any advice on getting form_id into the UDT.

    RHF

    Re: [solved] FormBuilder 0.7 - Change the destination email

    Posted: Mon Feb 18, 2013 1:09 pm
    by manuel
    Dear Robert,

    Code: Select all

    if($form_id == 4) {
    Thanks for noticing, i have changed the article accordingly!

    About the form_id:
    EDIT: I tested this and i do get the correct ID in the UDT... Oops, i tested this before correcting "$form_id == 4"...

    For the "*Call A User Defined Tag With the Form Results", did you activate the checkbox for "Export form reference to UDT as $params['FORM']? (do not do this if you are going to print_r($params) ):"?

    This should be unchecked...

    Greetings,
    Manuel

    Re: [solved] FormBuilder 0.7 - Change the destination email

    Posted: Mon Feb 18, 2013 2:30 pm
    by RHF
    Thanks Manuel,
    I really appreciate your response. Unfortunately, even when I uncheck the box, I still do not get the form_id using $params['form_id']. If I do a var_dump($params), I get the form variables but not the smarty variables. A great puzzle.
    Bob

    Re: [solved] FormBuilder 0.7 - Change the destination email

    Posted: Tue Feb 19, 2013 1:10 am
    by manuel
    Dear Bob,

    I looked again and it appears i have been too quick telling you it worked!
    Because i tested the $form_id output before correcting the "if ($form_id = 4)", the $form_id got set to 4 inside the UDT!

    Your solution seems to work fine so i'll update the article accordingly until someone enlightens us about a better way to grab the ID...
    RHF wrote:$actparams = $smarty->get_template_vars('actionparams');
    $form_id = $actparams['form_id'];
    Greetings,
    Manuel