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.

Making the Price/Quantity Field a Required Field

  1. I'm using the Price Quantity field as an essential part of my Gravity Form. I've noticed, though, that this field does not currently have an option for "Required Field".

    How can I make that a mandatory field?

    Here's the form:

    http://monetizemyhobby.com/spring-fling-2011/register/

    Thanks!

    Posted 13 years ago on Monday January 24, 2011 | Permalink
  2. Your best bet is to use a separate "Quantity" field which does have the ability to make it required. Alternately you can use the gform_validation to make sure the quantity of the product field is not empty.

    If you'd like to pursue the latter option, I can get you started with a snippet.

    Posted 13 years ago on Tuesday January 25, 2011 | Permalink
  3. Since I've already added a ton of work, i think it'd be easier to do the latter and not have to add a quantity to each section break by dragging them clear up the long form.

    Thanks for the snippet for gform_validation.

    Posted 13 years ago on Tuesday January 25, 2011 | Permalink
  4. Can I get that snippet of gform_validation?

    Thanks!

    Posted 13 years ago on Monday February 7, 2011 | Permalink
  5. Here is a gform_validation example:

    <?php
    add_filter('gform_validation', 'custom_validation');
    function custom_validation($validation_result){
    
    // set the form validation to false
    $validation_result["is_valid"] = false;
    $form = $validation_result["form"];
    
    // specify the first field to be invalid and provide custom validation message
    $form["fields"][0]["failed_validation"] = true;
    $form["fields"][0]["validation_message"] = "This field is invalid!";
    
    // update the form in the validation result with the form object you modified
    $validation_result["form"] = $form;
    
    return $validation_result;
    }
    ?>
    Posted 13 years ago on Monday February 7, 2011 | Permalink
  6. Thanks Carl. The reason I needed this was to cause a Product Quantity field to be mandatory to fill out.

    Which areas in the code here would I need to change?

    Here's the form (updating soon):

    http://monetizemyhobby.com/spring-fling-2011/register/

    Posted 13 years ago on Monday February 7, 2011 | Permalink
  7. Hi Moller,

    This will do the trick. Make sure you update the necessary pieces documented in the code: http://pastie.org/1538736

    Posted 13 years ago on Monday February 7, 2011 | Permalink