• Resolved mattyk1972

    (@mattyk1972)


    Hi there

    I’m trying to set up the contact form on a client’s site so that the e-mail address it is sent to depends on which option the site visitor selects from a drop down menu. Basically the client has representatives in different countries and wants the relevant country rep to receive the e-mail when the visitor selects which country they are from – so if they select UK it goes to the UK rep only, if they select USA it goes to the USA rep only, etc…

    The addition of pipes to the form code allows us to achieve this, and using the [_raw_field]) enables us to have the original value (rather than the conditional e-mail address) in the e-mail that’s received. However, we are also using the paid version of the Contact Form to DB Extension, and rather than capturing the original value from the form, it is capturing the conditional e-mail address. Basically we want the database to capture the value before the pipes, but it is capturing the e-mail after them.

    Is there a way to rectify what’s being captured in the database so that it contains the correct information?

    Thanks

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Sounds exactly like this post

    Plugin Author Michael Simpson

    (@msimpson)

    I added a new page to better describe the solution.

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Thanks for the quick response, and what looks to be a detailed solution. I’ll give it a try later on today and let you know how I get on.

    Matt

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Your fix worked a treat, now saving the chosen field to the database and still e-mailing to the conditional e-mail.

    Thanks again for such a speedy and effective solution.

    Matt

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Sorry to bother you again but I’ve hit another snag and was hoping you might be able to help. The fix you supplied above worked perfectly on the development site. We’ve recently transferred the site to the client’s hosting to go live, but now the conditional elements of the contact form submissions aren’t working properly.

    We have about 5 different countries for the site visitor to choose from, each with a corresponding e-mail address that we want to be notified depending on what the visitor selects. However, no matter which of the countries we select now, the same country is showing up in the database (and in the e-mails received).

    So no matter whether we select ‘UK’, ‘South Africa’ or ‘Other’, the e-mail says the visitor is in New Zealand, and New Zealand is the country that is stored in the database for that submission.

    I’ve tried reinstalling the code you supplied and updating the plugin but it still seems to be doing the same thing. I was wondering if you’ve got any idea why it was working fine with one hosting company, and now isn’t with another?

    Thanks again for your help.

    Matt

    Plugin Author Michael Simpson

    (@msimpson)

    I don’t know how that could happen.

    I suggest to try debugging by disabling the filter, then follow the “Debug” section at the bottom of this page (updated recently) to get it to log what is getting posted.

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Thanks for getting back to me so quickly. I tried your suggestion but don’t seem to be having any luck. Without boring you to death I thought it might be useful to let you know exactly what I’ve done to see if it sheds any light on why they setup isn’t working any more.

    I tested everything again on the development site and it all works fine. The only changes that have been made between that and the live site are moving to a different host and updating WordPress (to 3.4.2) and the other plugins. I updated the WordPress install and plugins on the development site, and everything still worked fine, so I can’t see how it can be that. Could it be an issue with the client’s hosting, maybe some settings for running scripts or something?

    In terms of the debugging, I didn’t seem to get anything but then I’m not 100% I had everything set up right. Here’s what I did:

    – Added an error_log.txt file to the contact-form-7-to-database-extension folder
    – Added a php.ini file to the contact-form-7-to-database-extension folder
    – Added the following to the php.ini file: error_log=/error_log.txt (should there be anything else?)
    – Removed the location filter code from the functions.php file
    – Added the debugging filter to the functions.php file

    I tried another form submission and was still getting the wrong location recorded in the database, but I didn’t get anything in the error file – but this might be the case if I’ve not set up the debugging correctly? I also tried a submission with the location filter and the debugging filter in the functions.php file, but still no errors and the wrong location.

    When I remove the location filter from functions.php altogether I get the original problem of the database recording the location e-mail rather than the location itself, but it is at least the right e-mail for the country that was selected on the form.

    I hope all that helps and I really appreciate your assistance with this. As I said, it was working fine on the development site, but since going live it seems to have developed a problem.

    Thanks again.

    Matt

    Plugin Author Michael Simpson

    (@msimpson)

    When I remove the location filter from functions.php altogether I get the original problem of the database recording the location e-mail rather than the location itself, but it is at least the right e-mail for the country that was selected on the form.

    That suggests there is clearly something wrong in the filter code. I looked over it again but I don’t see the problem. I posted what my log output was at the bottom of the solution page. I think you would need to compare it to your log output to see if there is something structurally different in your output.

    Thoughts on debugging (sorry if these are obvious to you):
    – Make sure your log file is writable by the process owner (“apache” maybe). if the file doesn’t already exist, try creating it and setting its ownership & write permissions.
    – Make sure the php.ini entry has the full absolute path to the target log file
    – I have my php.ini at the top level of the WP install, but I don’t know if that makes any difference.
    – In your filter functions, you could add a line at the beginning of it like error_log('function called'); Then look for that in the log file to verify that the function was a least called.
    – You can include both the debug logging filter function and your own as long as they have different names
    – Sanity-check that the function name matches the 2nd param to the add_filter('cfdb_form_data', '<FUNCTION_NAME>'); i.e. there are no typos.

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Through a bit of trial and error, as well as some serious head-scratching, I’ve managed to resolve the problem. The issue was pretty straightforward and I’m a bit embarrassed I didn’t spot it sooner.

    Because we don’t have representatives in every country, for a 2-3 of the locations we were using the same head office e-mail address. Looking at the code you supplied I’m guessing that the database interprets the location based on the e-mail address that matches it. So when more than one location has the same e-mail, it simply recognises the first location that matches that e-mail address, regardless of whether it was actually selected.

    Anyway, I’m pretty sure that’s what the problem was as I tried it with all different e-mails and it works fine. I think we’re just going to have to set up separate e-mails for all the different location options, unless there is another way round it by tweaking the code?

    Thanks for all your help with this.

    Matt

    Plugin Author Michael Simpson

    (@msimpson)

    Ahh…that makes sense.

    You might see if your mail server supports the “+” trick. You put in the same email with a “+” and text after that to make each entry unique. Like:

    somebody+location1@somewhere.com
    somebody+location2@somewhere.com
    somebody+location3@somewhere.com

    And see if the mail is still delivered all of them to the same email: “somebody@somwhere.com”

    Thread Starter mattyk1972

    (@mattyk1972)

    I did look at that but as our hosting allows unlimited email forwarding accounts, I just set up one of those for each location and forwarded them all the same email address where necessary.

    Thanks for all your help with this, I really appreciate it.

    Have a good Christmas.

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Sorry to bother you again but our client has asked another question I thought you might be able to answer.

    The database is working perfectly now and the client was wondering if there is any way to import contacts into the database? They get a lot of contacts from shows and events and they would like to be able to keep them all in one place (i.e. the CF7 database).

    Thanks for your help.

    Plugin Author Michael Simpson

    (@msimpson)

    There is not an easy way. I’ve been intending to add an CSV file import for quite some time but haven’t had time to do it.

    So you are stuck with trying to write a script you can run in MySQL to insert you data into the DB table that the plugin uses (wp_cf7dbplugin_submits). (I.e. if you have data in CSV, write a script in Perl or something like that to convert that into MySQL INSERT statements consistent with the schema).

    Table schema info

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Contact Form 7 Conditional Emails & Database Fields’ is closed to new replies.