PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Problem with default values

  1. sgarten
    Member

    Hi,

    Can you please help me with my code? I would like to specifically know what code to use and where to put the code. I think I should put it in functions.css.

    You can view the form at http://www.virtuecard.org. All I want, are for the fields to be required, but since I'm using default values someone can click the "request an invitation" button and it will submit the default values of "name" and "email". Instead, I'd like it to present an error message if the default values are presented.

    -----
    The form ID is 13 and the "name" field is field 4 and the "email" field is field 3.

    Here's the code I added to my functions.php file that didn't work. I only attempted fixing field 4, but since that didn't work, I didn't code out for field 3 yet.
    -----

    <?php

    add_filter('gform_validation_13', 'custom_validation');
    function custom_validation($validation_result){
    $form = $validation_result["form"];

    //supposing we don't want input 1 to be a value of 86
    if($_POST['input_4'] == name){

    // set the form validation to false
    $validation_result["is_valid"] = false;

    //finding Field with ID of 1 and marking it as failed validation
    foreach($form["fields"] as &$field){

    //NOTE: replace 1 with the field you would like to validate
    if($field["id"] == "4"){
    $field["failed_validation"] = true;
    $field["validation_message"] = "This field is invalid!";
    break;
    }
    }

    }

    //Assign modified $form object back to the validation result
    $validation_result["form"] = $form;
    return $validation_result;

    }

    ?>

    Posted 10 years ago on Monday July 1, 2013 | Permalink
  2. Richard Vav
    Administrator

    You might try using a placeholder plugin rather than faking the placeholders with the default value. I think there are currently two plugins in the WordPress plugin repository
    http://wordpress.org/extend/plugins/gravity-forms-placeholders/
    http://wordpress.org/extend/plugins/gravity-forms-auto-placeholders/

    Posted 10 years ago on Monday July 1, 2013 | Permalink
  3. sgarten
    Member

    Thanks, Richard.

    That did the trick. Only issue now is that it error notifications make the page look all messy.

    Is there a way, perhaps via css, to turn off the error messages? In other words, I still want the two fields "required", but if a user doesn't fill them out correctly I just want for the form not to process.

    I greatly appreciate your help.

    Posted 10 years ago on Monday July 1, 2013 | Permalink
  4. Richard Vav
    Administrator

    You would use CSS to hide the error notifications, you can find examples of how to target the various elements of Gravity Forms with CSS in the documentation, the following link is for the section regarding validation errors http://www.gravityhelp.com/documentation/page/CSS_Targeting_Samples#Validation_Errors

    Try adding the following to your theme stylesheet or wherever you add custom CSS

    #gform_wrapper_13 .validation_error, #gform_wrapper_13 .gform_body .gform_fields .gfield_error .validation_message {
        display:none !important;
    }
    #gform_wrapper_13 li.gfield.gfield_error.gfield_contains_required {
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
        border: none !important;
    }
    #gform_wrapper_13 li.gfield.gfield_error.gfield_contains_required div.ginput_container {
        margin-top: 0 !important;
    }
    Posted 10 years ago on Tuesday July 2, 2013 | Permalink
  5. sgarten
    Member

    Thanks, Richard that worked to hide the error notifications. The only issue now is this:

    The form does not require a full email address. Try typing in just any only characters and it will accept whatever you put in.

    How do I make the email box accept only full emails like: email@email.com?

    Posted 10 years ago on Tuesday July 2, 2013 | Permalink
  6. Richard Vav
    Administrator

    Can you go to the Gravity Forms general settings page and make sure 'Output HTML5' is set to 'Yes', then edit your form and make sure you are using an email field (advanced fields panel) and not a single line text field.

    Posted 10 years ago on Tuesday July 2, 2013 | Permalink
  7. sgarten
    Member

    Richard, that did the trick. Thank you again!

    Posted 10 years ago on Monday July 8, 2013 | Permalink
  8. Richard Vav
    Administrator

    You're welcome.

    Posted 10 years ago on Tuesday July 9, 2013 | Permalink

This topic has been resolved and has been closed to new replies.