Support

Home Forums Event Espresso Premium How to handle registration form error display elegantly (2)

How to handle registration form error display elegantly (2)

Posted: August 25, 2020 at 5:32 pm

Viewing 2 reply threads


mbeede@tracom.com

August 25, 2020 at 5:32 pm

(NOTE: I am resubmitting this topic because for some reason I can’t reply to my original topic post – I get logged out of my account automatically as soon as I click on the link for my post – not sure why)

MY ORIGINAL POST
****************
Greetings – I have an event registration form with four fields: First Name, Last Name, Email Address, and Company Code. The Company Code had to be added as a new “question” of type text.

I would like to compare this input Company Code to a Company Code that is provided on the Event page itself via Custom Field. If they don’t match I would like to highlight the field and put an error message underneath it (just like your default behavior for required fields)

So here is a snippet of code in my submit override method in my PHP plugin:


// Check if the event client code matches the input client code
// Get the target client code
$targetCode = get_post_meta($event->ID(), ‘max_client_code’, true);
error_log(print_r(‘TARGET CODE: ‘ . $targetCode, true));

// Get the input client code
#inputCode = $registration->answer_value_to_question(12);
error_log(print_r(‘INPUT CODE: ‘ . $inputCode, true));

// Then compare them and if they don’t match display a field level error

Hopefully you get the idea. So how can highlight the field and display an error message underneath it in PHP if the 2 codes don’t match? OR is there a better way to implement this that I am not seeing?

Thanks in advance,
Mark

TONY’S REPLY
************
Hi there,

Sounds like you could use the FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process hook to do what you are requesting.

That allows you to stop processing and return an error onto the page, you can also specify which field your error should target.

Take a look here: https://github.com/eventespresso/event-espresso-core/blob/0162cae7ab1d97d52130e87079931b992a691e5e/modules/single_page_checkout/reg_steps/attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php#L1038-L1048

************
NEW QUESTION
************
You mention “you can also specify which field your error should target”
Can you please expand on this? How do I go about doing this and how do I tie the hook to CSS to highlight the field in error like you do with required fields on the registration form.

Thanks, Mark


mbeede@tracom.com

August 26, 2020 at 12:28 pm

PLEASE DELETE OR CLOSE THIS POST. It is a duplicate of my other one that now seems to be working properly for posting a reply.


Tony

  • Support Staff

August 28, 2020 at 4:55 am

Closing this out, see:

https://eventespresso.com/topic/how-to-handle-registration-form-error-display-elegantly/

Viewing 2 reply threads

The support post ‘How to handle registration form error display elegantly (2)’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso