How adding error text in wpcf7_before_send_mail?
-
Hello. I have a question about aborting send email and custom error message. In my form I have block with section for selecting time (radio buttons). But this section is dynamic. Available times I can get only from request to api. I did not find anything better than making a js request (form located in popup, no need adding radio buttons immediately), getting data and inserting it into a form. It works, I get time value that user selected, but I have one problem. If user spend more time to send form , time value that user select may be busy by another user. I have api point for checking if selected time is available. So I use wpcf7_before_send_mail hook. In this hook I get selected value and send request to api for checking if it available now. But how I can send error to user, if time is not available?
function qs_api_call($contact_form, &$abort, $submission) { // Some logic.. // If api call say "not available" I must stopped sending form and send custom error message to form message block $properties = $contact_form->get_properties(); $properties['error']['message'] = 'My custom error message'; // I don't know how I can do something like this $contact_form->set_properties($properties); $abort = true; // Is it stoped form submitting? return contact_form; }And user after click send button get my custom message, that error happened.
The topic ‘How adding error text in wpcf7_before_send_mail?’ is closed to new replies.