• Resolved tkruse

    (@tkruse)


    hello together,

    i′ve seen a solution here for a static adress of the form id.

    in my case i′m using on two posts 2 different forms.
    in each post each user should be able to fill out and send the form once.

    to solve this i would like to add a variable which reads the id of the actual form and then replace this to the code

    $formName = 'email_form'; // Name of the form containing this field

    but how i can get this working? i′ve tried this:
    $formName = $cf7->id; // Name of the form containing this field
    but no chance…

    would be great if you could help me to figure it out !!

    thx & cheers, tom

    https://www.ads-software.com/plugins/contact-form-7-to-database-extension/

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

    (@msimpson)

    I don’t understand if you want the user to be able to (1) submit once only for both of the 2 forms or (2) once for each form.

    (1)
    Change
    $formName = 'email_form';
    to
    $formName = array('form_name1', 'form_name2');
    and change
    if($name == $fieldName) {
    to
    if(in_array($name, $fieldName) {

    (2)
    Make a copy of the my_validate_email and name it something else.
    Set the values of $formName and $fieldName
    $fieldName must be a unique value not appearing on any other form
    Copy the add_filter call, passing the name of the new copy of my_validate_email

    Thread Starter tkruse

    (@tkruse)

    hi michael,
    thx for your help !!!!

    i have more than 50 forms where to check if the user has submitted to each once a time. isn′t there a dynamically way to solve that for (2)?

    as an idea:
    – each form has it′s name in cf7. when a post was loaded with a form, the form name will be stored in the variable $formName.
    – then it will be checked if the email was already submitted tothat actual loaded $formName. if so, no submission allowed.
    is something like that possible, too?

    would be great to get on in this case !!

    thx & cheers, tom

    Plugin Author Michael Simpson

    (@msimpson)

    No that doesn’t make sense. When you click the submit button, before the form is submitted, the value of the email field is sent to the validation function that you made. Your function receives the field name and field value but not the form name. Once that passes, then the form is submitted and CFDB has the form name in that.

    You could ask on CF7 forum about CF7 supporting this.

    Thread Starter tkruse

    (@tkruse)

    hmm.. what about the opposite?
    check if the email already exists… if yes, go on, if not refuse the submit.

    Plugin Author Michael Simpson

    (@msimpson)

    You can code your validation function however you like.

    Hi, i need help for preventing duplicate for 1 form and 2 tables.
    Example:

    table category
    table moto_number

    When 2x i send form with category_1 and number_1 = ERROR (duplicate)
    When 1x i send form with category_1 and number_1 and after i send form with category_2 and number_1 = OK.

    I will unique moto_number for one category and no for every categories.
    Thx for help. Sorry for my bad english. I am from Czech Republic.

    Plugin Author Michael Simpson

    (@msimpson)

    Preventing Duplicate Submissions from CF7 shows where you can add code to check for duplication.

    I tried it, but it did not solve my problem.
    I need a unique moto_number for every moto_category.
    This code checks the item from all tables.

    Example:

    In order: Moto number 1 in category 1, moto number 1 in Category 2.

    Not in order: Moto number 1 in category 1, moto number 1 in category 1

    it will work?

    Plugin Author Michael Simpson

    (@msimpson)

    You would have to adapt the code to suit your needs. In the function is_already_submitted you might add additional criteria to “filter” to search within a category.

    It occurred to me too. But how to use it when the category name is also on the form? Can I use $ _POST function to filter?

    Example:

    $atts['filter'] = "$fieldName=$fieldValue&&kategorie=".$_POST["kategorie"]."";

    Is it right?

    It works. Thx for tip.:)

    Is there any code or plugin that is supported by contact form 7 and can prevent duplicate phone number submissions..?

    Michael, I have a related question:

    I followed your solution at https://cfdbplugin.com/?page_id=904, and it seems to be working, except for one issue. It blocks a duplicate form submission, but it doesn’t use the error message I inputted into the Shortcodes, Actions, and Filters. Instead, it uses the generic error message from Contact Form 7 for any submission that fails to go through. How can I make the duplicate form submission error message override the generic failed submission message?

    Thanks!

    Plugin Author Michael Simpson

    (@msimpson)

    My example might be a little out of date.

    Look at this:
    https://contactform7.com/2015/03/28/custom-validation/

    Do you see how the $tag variable is different from my example? I think things have changed in CF7 since I created my example.

    I looked at the link and changed the code, but haven’t gotten it to work. Can you tell me if you see what I did wrong? (note, I used a dynamic hidden field to add the user’s email address)

    Here is what I had from your example:

    function my_validate_email($result, $tag) {
    $formName = ‘Form 1’;
    $fieldName = ‘dynamichidden-11’;
    $name = $tag[‘name’];
    if($name == $fieldName){
    $valueToValidate = $_POST[$name];
    if (is_already_submitted($formName, $fieldName, $valueToValidate)) {
    $result->invalidate($name, ‘You have already submitted a rating.’);
    }
    }
    return $result;
    }

    And this is what I changed it to:

    function my_validate_email($result, $tag) {
    $formName = ‘Form 1’;
    $fieldName = ‘dynamichidden-11’;
    $tag = new WPCF7_Shortcode( $tag );
    if($tag == $fieldname){
    $valueToValidate = $_POST[$tag];
    if (is_already_submitted($formName, $fieldName, $valueToValidate)) {
    $result->invalidate($tag, ‘You have already submitted a rating.’);
    }
    }
    return $result;
    }

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Preventing Duplicate Submissions’ is closed to new replies.