• Resolved raggiorama

    (@raggiorama)


    Hello! I’ve added a custom field following the instructions here https://givewp.com/documentation/developers/how-to-create-custom-form-fields/.

    It is a text field that should contain a fiscal code number (PAN number for Indian donors).
    Specifically I have a function that via regex checks if the input string is correct and I’d like to know which GIVE actions should I hook that function to, so that if the input value is not valid the form is not processed and an error message appears like the one for required fields.

    I’ve been struggling with this for a while now and any help is greatly appreciated. Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    Hi there,

    We can help you best if you provide us with the code you’re attempting to use. Paste a link here to a Gist or similar and we’ll take a look.

    Thanks!

    Thread Starter raggiorama

    (@raggiorama)

    Hi Matt,
    thank you for getting back to me. I looked into the repo and found a hook
    “give_pre_process_donation” inside inc/process-donation.php that seems to be working.
    Here’s the link to code. I tested it a few times and it seems to be working but I don’t know if that’s the right place to make that check happen…

    I also see that the error messages get printed near the form submit button: is there a better way to print the error messages, by using ajax perhaps? I would also like to avoid the error messages to be printed twice if, for example, the user writes two consecutive wrong PAN numbers.

    Thank you again for your prompt reply, I appreciate it.
    Laura

    Plugin Contributor Matt Cromwell

    (@webdevmattcrom)

    HI there,

    The best would be to use the hook give_checkout_error_checks We have a sample snippet here that shows how you can do custom field validations:
    https://github.com/impress-org/givewp-snippet-library/blob/master/form-customizations/validate-donation-amount.php

    Thanks!

    Thread Starter raggiorama

    (@raggiorama)

    Thank you, Matt! That works as I intended.
    Best wishes,
    Laura

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Implement custom validation logic’ is closed to new replies.