Form Module email subject

edited January 2016 in Modules
Hi
I am using the forms module in a site and want to make the subject line of each email to be unique to that email. This prevents the mail form getting attached to others emails (google apps) in the inbox.
The forms module is been used as a contact form. I have been able to add a datetime() to the subject in the config/forms.php file and that works great.
I'd like to be able to add the senders name too so that the emails are easily identified in the google mail inbox list.
Can anyone please explain how this might be done via the CMS where the form is created.
Thanks

Comments

  • edited 10:03PM
    How are you currently outputting the form on the page? e.g: <?=form('contact')?>
    The forms.php config file has a default 'email_subject' line and 'email_from' parameter that is for all forms, however, you can specify it at the form level as well:
    <?=form('contact', array('email_subject' => 'My subject line...'))?>
  • edited 10:03PM
    Thanks that good to know. I am using <?=form('contact')?> but what I would like to do is have the emails subject line contain the name of the name field. Will I be able to do that using a hook?
  • edited 10:03PM
    You can use the "post_process" hook. The first parameter passed to your hook will be an instance of the form object itself in which you can set the property.
  • edited 10:03PM
    I couldn't get the hook to work. May be if you have time you could explain in more detail.
    However I altered the function in Fuel_Forms.php to

    protected function get_email_subject() { if (empty($this->email_subject)) { return $this->fuel->forms->config('email_subject'); } $email_subject = str_replace(array('{{', '}}'), array('{', '}'), $this->email_subject); $output = parse_template_syntax($email_subject, $_POST, TRUE); return $output; //return $this->email_subject; }

    This allows me to add a email subject line via the CMS for that form with {{name}} template tag so that it's parsed with the $_POST['name'] value

    It's a hack to the core forms code and Im sure theres a better way to do this...
  • edited 10:03PM
    To use a hook, you can do the following:

    1. Create a hook function and place it your fuel/application/helpers/my_helper.php like so:
    function my_form_post_process($form) { $form->email_subject = 'This is a TEST!!!'; }
    2. Then in your fuel/application/config/forms.php, add the following to your $config['forms']['forms']['my_form'] where my_form is the name of your form:
    $config['forms']['forms'] = array( 'my_form' => array( // ..... additional config stuff goes here 'hooks' => array('post_process' => 'my_form_post_process'), ) );
  • edited 10:03PM
    Thanks but still not calling the my_form_post_process function.

    i set it up as you have above but changed the my_form to contact

    It looks like that the hook added to the config>forms.php file is not been added to $hooks on the form object.

    I added it manually into
    protected $hooks = array('post_process' => 'my_form_post_process');
    in the Fuel_forms.php file and your example above works and changes the email subject to: This is a TEST!!!

    Any further help would be appreciated.
  • edited 10:03PM
    Hmm... if you debug fuel/modules/forms/Fuel_forms.php around line 747 does it have the name of the function? I tested the method above and it seemed to work OK for me.
    $this->call_hook('post_process');
Sign In or Register to comment.