[solved] FormBuilder 0.7 - Change the destination email

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
eoto88

[solved] FormBuilder 0.7 - Change the destination email

Post 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.
Last edited by eoto88 on Fri Jun 03, 2011 6:48 pm, edited 3 times in total.
eoto88

Re: FormBuilder 0.7 - How to change the destination email

Post 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!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: FormBuilder 0.7 - How to change the destination email

Post 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');
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
eoto88

Re: FormBuilder 0.7 - How to change the destination email

Post 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!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: FormBuilder 0.7 - How to change the destination email

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
manuel
Power Poster
Power Poster
Posts: 350
Joined: Fri Nov 30, 2007 9:15 am

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

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
RHF
Forum Members
Forum Members
Posts: 20
Joined: Sun Jan 23, 2011 1:55 am

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

Post 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
    User avatar
    manuel
    Power Poster
    Power Poster
    Posts: 350
    Joined: Fri Nov 30, 2007 9:15 am

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

    Post 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
    Do you like your open source cms? Buy from the CMSMS partners || Donate
    RHF
    Forum Members
    Forum Members
    Posts: 20
    Joined: Sun Jan 23, 2011 1:55 am

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

    Post 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
    User avatar
    manuel
    Power Poster
    Power Poster
    Posts: 350
    Joined: Fri Nov 30, 2007 9:15 am

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

    Post 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
    Do you like your open source cms? Buy from the CMSMS partners || Donate
    Locked

    Return to “Modules/Add-Ons”