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.

hooks to clear fields and do custom validation

  1. monicanina
    Member

    Just wondering if I can massage the form data passed to gform_pre_submission and validate it somehow? I am going to use the hook to call some other services, but then I don't necessarily want to save those fields in the entries table, so I need to clear them out. Is it as easy as unset($form[field])? Also, gform_pre_submission is run after validation it says, so is there no means of do some custom validation? If not, any chances of a gform_pre/post_validation hook to enter the plugin anytime soon? I envision it to have access to the form data and the error object...

    [ and a side note, the system where the forum email has to be the same as the payer of the license is a bit odd - I had my client buy the license, so I have to log in with her account to see the docs and can't really subscribe to this thread... feel free to bump me at marco@mimecom.net ]

    [ second side note: the plugin, with it's shortcomings, have still saved me sooo much time! thank you! more license fees coming your way when I get more clients to use you.. ]

    Posted 13 years ago on Tuesday November 2, 2010 | Permalink
  2. The system where the forum email has to be the same as the payer of the license is done this way because only the license holder receives support and the only way we can identify a customer is by email.

    It identifies you by payment email address and gives you access to the private areas of the support site if you have a valid payment email address. It's similar to registering with any web service you pay for. The person who owns the license is the one who receives support access.

    There is a gform_validation hook that can be used to create custom validation.

    <?php
    add_filter("gform_validation", "custom_validation", 10, 2);
    ?>

    Here is an 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 Tuesday November 2, 2010 | Permalink
  3. monicanina
    Member

    Ah! That's great! Still a little unsure which hook is best to modify submitted data. Say, if the customer submits a password, I first want it validated and then probably hashed before getting saved to the database or handed off to other services.

    I understand that I can remove the last entry saved to the database with the gform_post_submission hook (that kind of solves the above) but I'd rather certain things doesn't even touch the database and in certain cases the entire record should not be saved, just handed off to a handler. Is there a a way to do that by returning false, null, empty array or an array with empty fields from gform_post_submission ?

    Too bad with the licensing thing - I assume I can't get support since I 'impersonate' my client then:) No worries, I do understand it's probably the easiest way to implement it... Just a tiny thorn:)

    Posted 13 years ago on Tuesday November 2, 2010 | Permalink