Is there any custom event for error or submitting?

[ad_1]

Hi @ultigendlemate

As for showing error message:

This modified code should also be showing message on submission fail:

<?php

function wpdocs_theme_name_scripts() {
	wp_enqueue_style( 'toastify-custom', 'https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css' );
	wp_enqueue_script( 'toastify-custom', 'https://cdn.jsdelivr.net/npm/toastify-js', '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );

add_action( 'wp_footer', function(){ ?>
<script>
	(function($){
		$(function(){
			if( window.HUI ){
				var _popups = $(".hustle-popup");

				if( _popups.length ){
					_popups.on("hustle:module:submit:success", function(){
						handle_hustle_submission_event( $(this) );
					});
					_popups.on("hustle:module:submit:failed", function() {
						handle_hustle_submission_error_event( $(this) );
					});
				}
				function handle_hustle_submission_event( _element ){

					Toastify({
                        text: "This is a toast",
                        duration: 3000
                    }).showToast();

				}
				function handle_hustle_submission_error_event( _element ){

					Toastify({
                        text: "This is a toast",
                        duration: 3000
                    }).showToast();

				}				
				
			}
		});
	})(window.jQuery)
</script>
<?php }, 21 );

Note: this will only show predefined message; to intercept actual error you’d need some additional JS to read content of the error from the displayed error block, hide that block and pass the error to toast; this should be doable, I believe, but it would require more custom code and it’s out of the scope of our assistance, I’m afraid.

As for showing image:

The simplest way to show image would be to use “avatar” option key. You have these lines in the code:

Toastify({
	text: "This is a toast",
	duration: 3000
}).showToast();

so you can add “avatar” option like this

Toastify({
	text: "This is a toast",
	avatar: 'URL_OF_YOUR_IMAGE_FILE_HERE',
	duration: 3000
}).showToast();

Alternatively, you can instead add a custom class name and then simply use a regular CSS to style it (e.g. adding image as background, positioned accordingly):

Toastify({
	text: "This is a toast",
	className = 'toast-message',
	duration: 3000
}).showToast();

Or you can combine the two:

Toastify({
	text: "This is a toast",
	avatar: 'URL_OF_YOUR_IMAGE_FILE_HERE',
	className = 'toast-message',
	duration: 3000
}).showToast();

Best regards,
Adam

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer