• rg88j

    (@rg88j)


    Hi everyone, I seem to have stumbled upon an issue which I just can’t seem to solve on my own.

    I have a (private) page with a Customer form which stores company information of each new customer (company names, e-mail addresses, telephone numbers and websites) in associated database, including customer numbers which my company provides. Then I have a (public) page with an Appointment form which my known customers can use to make appointments with my company.

    The issue:
    I want all company fields to automatically get pre-filled once the customers manually fill in their associated customer numbers. Does anyone know how to get this done?

    FYI:
    Michael Simpson’s tutorials on how to create shortcodes to access form data via PHP (https://cfdbplugin.com/?page_id=444 and https://cfdbplugin.com/?page_id=367) have helped me quite a bit, though. I found out how to have my Appointment form pull a specific company name from my Company data database and display it in the Company name field based on the customer number “123456” I put as the array(‘search’ => criteria in the shortcode:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
    $exp = new CFDBFormIterator();
    $exp->export('Company data', array('search' => '123456'));
    while ($row = $exp->nextRow()) {
    echo $row['Company name'];
    }

    Secondly, I added a dynamic text field into my Appointment form linked to above shortcode, which nicely displays the company name associated with customer number “123456”:

    Company name:
    [dynamictext Company name 'shortcode']

    The problem with this, though, is that it pulls and displays ALL company names from the database CONTAINING the customer number criteria in ANY of the database fields. So if a company’s telephone number contains the criteria “123456”, that company will also be pulled and displayed from the database, while I want it only to pull and display one result, which is the company containing that exact customer number.
    Also, the array(‘search’ => criteria in this case is static. I want it to be variable, thus to be linked to the Customer number input field on my Appointment form, so that the Company name field (and of course all other company fields) automatically get pre-populated when customers decide to make an appointment.

    Any help is appreciated.

    • This topic was modified 8 years ago by rg88j.
Viewing 1 replies (of 1 total)
  • Thread Starter rg88j

    (@rg88j)

    I changed the following line:

    $exp->export('Company data', array('search' => '123456'));

    to:

    $exp->export('Company data', array('filter' => "Customer number=123456"));

    and now it only displays the company associated with that specific customer number.

    I still want to link the filter criteria in my shortcode to the Customer number input field on my form. Does anyone know if/how that can be done?

    • This reply was modified 8 years ago by rg88j.
    • This reply was modified 8 years ago by rg88j.
Viewing 1 replies (of 1 total)
  • The topic ‘Pre-fill all fields based on one specific field from database’ is closed to new replies.