Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Modify posted data before sending

  • Resolved e

    (@xaviesteve)


    I am trying to edit the $wpcf7 object data but it ignores it, this is the code:

    function wpcf7_modify_this(&$wpcf7_data) {
      $wpcf7_data->mail->recipient = "Mark <mark@gmail.com>";
    }
    add_action("wpcf7_before_send_mail", "wpcf7_modify_this");

    I have been able to cancel emails by adding:
    $wpcf7_data->skip_mail = true;

    But changing any other parameter such as the recipient doesn’t work.

    Any ideas??

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 7 replies - 1 through 7 (of 7 total)
  • e

    (@xaviesteve)

    Ok, finally got it. It turns out the WPCF7 thing is an Object with Arrays inside so it should be called like:
    $wpcf7_data->mail['recipient'] = "Mark <mark@gmail.com>";

    Hope that helps 🙂

    what would you like to do with the posted data?

    e

    (@xaviesteve)

    Hi strigga,

    You can do pretty much anything, some examples:

    1) if the user typed in the word “support” or “help” you could change the recipient to support@company.com, but if it found “business enquiry” forward it to sales@company.com.

    2) Same goes for a City field, if the user is in London you could send the email to the London branch.

    3) Or if the form was submitted on a weekend, when the offices are closed, you can send a confirmation email like “Thanks for your email, unfortunately we are out of the office, will get back to you on Monday“.

    4) If there is a budget field and the user types in “1,000” then forward it to sales@company.com, but if the user types in “10,000,000” then the boss will probably want to deal with that juicy client himself.

    There’s plenty of examples really, the idea is to have fewer forms on the site (or even just one) which then through some smart coding can do custom actions or change certain things.

    Very handy, cheers mate

    @ e

    What to do when you have multiple forms (contact forms and apply forms) on you’re website? How do you determine when this function must be executed? My custom before mail send function should only be executed with the apply forms.

    e

    (@xaviesteve)

    @ toomaat

    Each form has an ID: $wpcf7_data->id so once you know the ID of the Apply forms you can put a conditional if($wpcf7_data->id == 123) and take action only for that form

    Thx!

    In the mean time I also found the solution ‘how to handle with multiple forms”.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Contact Form 7] Modify posted data before sending’ is closed to new replies.