Posted: August 19, 2020 at 5:34 pm
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:
// Get the input client code
// 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,
Sounds like you could use the
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
You mention above “you can also specify which field your error should target”
Mark, my apologies.
You can see this in action within our WP user integration add-on HERE
Which then uses it’s own JS loaded on SPCO, see HERE
What you may be better doing is using some PHP to add the events meta value to the DOM/global JS var, then add your own JS with a listener on the Company question. Compare the value on change with the meta value you added to the page earlier, disable the submit button if invalid and/or add the message to the field.