Forum Replies Created

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    I’ve always struggled with the debugging process so I had another look at the code and seem to have got it to work by adding two bits of code – see below:

    function location_form_handler($formData)
    {
        $formName = 'Brochure Request Form'; // change this to your form's name
        $fieldName = 'country'; // change this to your field's name
        if ($formData && $formName == $formData->title && $formData->scanned_form_tags) {
            $emailSelected = $formData->posted_data[$fieldName];
            $valueSelected = null;
            foreach ($formData->scanned_form_tags as $tag) {
                if ($tag['name'] == $fieldName) {
                    foreach ($tag['raw_values'] as $rawValue) {
                        // value|email
                        $valuesArray = explode('|', $rawValue);
                        if (count($valuesArray) == 2 && $valuesArray[1] == $emailSelected) {
                            $valueSelected = $valuesArray[0];
                            break;
                        }
                    }
                }
                if ($valueSelected != null) {
                    break;
                }
            }
            if ($valueSelected != null) {
                $formData->posted_data[$fieldName] = $valueSelected;
                $formData->posted_data[$fieldName . '_email'] = $emailSelected;
            }
        }
        return $formData;
    }
    add_filter('cfdb_form_data', 'location_form_handler');
    
    function location_form_handler2($formData)
    {
        $formName = 'USA Booking Form'; // change this to your form's name
        $fieldName = 'country'; // change this to your field's name
        if ($formData && $formName == $formData->title && $formData->scanned_form_tags) {
            $emailSelected = $formData->posted_data[$fieldName];
            $valueSelected = null;
            foreach ($formData->scanned_form_tags as $tag) {
                if ($tag['name'] == $fieldName) {
                    foreach ($tag['raw_values'] as $rawValue) {
                        // value|email
                        $valuesArray = explode('|', $rawValue);
                        if (count($valuesArray) == 2 && $valuesArray[1] == $emailSelected) {
                            $valueSelected = $valuesArray[0];
                            break;
                        }
                    }
                }
                if ($valueSelected != null) {
                    break;
                }
            }
            if ($valueSelected != null) {
                $formData->posted_data[$fieldName] = $valueSelected;
                $formData->posted_data[$fieldName . '_email'] = $emailSelected;
            }
        }
        return $formData;
    }
    add_filter('cfdb_form_data', 'location_form_handler2');

    Thanks for all your help.

    Matt

    Thread Starter mattyk1972

    (@mattyk1972)

    Hi Michael

    Thanks for getting back to me so quickly. I tried the code you provided but for some reason it’s still not giving the results we’re looking for. We’re just getting the e-mail address we’ve added after the pipes instead of the field value.

    I tried changing the existing code we had for the original conditional e-mail form, and adding in the values of the new, second form, and that seemed to work fine, so I don’t think there’s an issue with the new form itself. I’ve attached the original code I was using which seems to be working fine (for either conditional e-mail form):

    function location_form_handler($formData)
    {
        $formName = 'Brochure Request Form'; // change this to your form's name
        $fieldName = 'country'; // change this to your field's name
        if ($formData && $formName == $formData->title && $formData->scanned_form_tags) {
            $emailSelected = $formData->posted_data[$fieldName];
            $valueSelected = null;
            foreach ($formData->scanned_form_tags as $tag) {
                if ($tag['name'] == $fieldName) {
                    foreach ($tag['raw_values'] as $rawValue) {
                        // value|email
                        $valuesArray = explode('|', $rawValue);
                        if (count($valuesArray) == 2 && $valuesArray[1] == $emailSelected) {
                            $valueSelected = $valuesArray[0];
                            break;
                        }
                    }
                }
                if ($valueSelected != null) {
                    break;
                }
            }
            if ($valueSelected != null) {
                $formData->posted_data[$fieldName] = $valueSelected;
                $formData->posted_data[$fieldName . '_email'] = $emailSelected;
            }
        }
        return $formData;
    }
    add_filter('cfdb_form_data', 'location_form_handler');

    And here is the new code I tried to add to replace it, I’m not sure if there’s something in there that I’ve missed out but the field we used the pipes in always comes back as the e-mail address, rather the value the user selected. I even tried changing the field names so they were different n case that was an issue, but it still gave the same results.

    function location_form_handler($formData, $formName, $fieldName)
    {
        if ($formData && $formName == $formData->title && $formData->scanned_form_tags) {
            $emailSelected = $formData->posted_data[$fieldName];
            $valueSelected = null;
            foreach ($formData->scanned_form_tags as $tag) {
                if ($tag['name'] == $fieldName) {
                    foreach ($tag['raw_values'] as $rawValue) {
                        // value|email
                        $valuesArray = explode('|', $rawValue);
                        if (count($valuesArray) == 2 && $valuesArray[1] == $emailSelected) {
                            $valueSelected = $valuesArray[0];
                            break;
                        }
                    }
                }
                if ($valueSelected != null) {
                    break;
                }
            }
            if ($valueSelected != null) {
                $formData->posted_data[$fieldName] = $valueSelected;
                $formData->posted_data[$fieldName . '_email'] = $emailSelected;
            }
        }
        return $formData;
    }
    
    // Form 1
    function location_form_handler_form1($formData) {
        $formName = 'Brochure Request Form'; // change this to your form's name
        $fieldName = 'country'; // change this to your field's name
        location_form_handler($formData, $formName, $fieldName);
    }
    add_filter('cfdb_form_data', 'location_form_handler_form1');
    
    // Form 2
    function location_form_handler_form2($formData) {
        $formName = 'USA Booking Form'; // change this to your form's name
        $fieldName = 'country'; // change this to your field's name
        location_form_handler($formData, $formName, $fieldName);
    }
    add_filter('cfdb_form_data', 'location_form_handler_form2');

    Your patience and help is really appreciated.

    Thanks

    Matt

    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.

    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

    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

    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

    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

    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

    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 there

    I understand why the error message is being generated, because the plugin can’t find the form, but what I don’t understand is why the form appears in the CF7 dashboard, but isn’t being saved to the database.

    Thanks

    Thread Starter mattyk1972

    (@mattyk1972)

    Thanks for responding. You mentioned that this is apparently not related to the CF7 plugin – do you know why?

    Thanks again.

    Thread Starter mattyk1972

    (@mattyk1972)

    Thanks for the suggestions. The z.index one looks as though it might be the mot likely but I’m still not sure how to implement it in WordPress.

    I found this article that outlines the steps:
    https://cherny.com/webdev/11/dual-background-images

    I’m happy enough making the CSS changes, especially as the theme I’m using has a custom CSS section, but to which file do I add the the html bit that creates the extra div?

    Not sure if it’s important but my site is tbmystery.k-toomarketing.co.uk

    Thanks for the help.

    Thread Starter mattyk1972

    (@mattyk1972)

    Cheers RVoodo, but SS_Minnow you were spot on.

    I had an SEO plug in that was obviously overriding the header.php file. Put what I wanted in my title tags, saved and there it was.

    God bles you and all who sail in you ??

Viewing 13 replies - 1 through 13 (of 13 total)