How can I set a form as invalid dynamically?
-
I use wppb(https://wppb.me/) for my plugin and I#d like to set a form as invalid.
I can set a custom message with wpcf7_display_message, but I can’t set a form as invalid, with a red background, and stop submission.
I add action like this:
private function define_public_hooks() { $plugin_public = new Unitel_Sim_Registration_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wpcf7_before_send_mail', $plugin_public, 'before_email_send', 10, 2 ); }
And then
public function before_email_send( $contact_form ) { $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); $email = sanitize_email($posted_data['uscr-email']); $cvr = sanitize_text_field($posted_data['uscr-cvr']); $customer = $this->customer_exists( $email, $cvr ); if ( is_null( $customer ) ) { $this->login_message('Customer not found'); // I set a message, but it has a green background and form submits // I would like to show a message in a red background, indicating an error and stop it from submission // how can I do that? } }
public function login_message( $messages ) { add_filter('wpcf7_display_message', static function ( $message, $status ) use ($messages) { return $messages; },10,2); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How can I set a form as invalid dynamically?’ is closed to new replies.