Toast Notifications for Contact Form

2 replies · opened Jan 16, 2017

Ccody-frewJan 16, 2017

I am trying to configure Toast Notifications like you have on http://themes.semicolonweb.com/html/canvas/contact.php, but I'm not seeing where to configure that in the documentation.

Right now, when the form is completed, it takes the visitor to blank .php page with the success message on there. How do I change that to stay on the page and use the Toast-Message notifications instead?

http://dabbledigital.com/support.html

Also, how can i configure the Required Field errors?

Thanks!

Ccody-frewJan 16, 2017
// Form Processing Messages
$message_success = 'We have **successfully** received your Message and will get Back to you as soon as possible.';

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
	if( $_POST['template-contactform-email'] != '' ) {

		$name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
		$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
		$phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
		$website = isset( $_POST['template-contactform-website'] ) ? $_POST['template-contactform-website'] : '';
		$subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
		$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';

		$subject = isset($subject) ? $subject : 'New Message From Contact Form';

		$botcheck = $_POST['template-contactform-botcheck'];

		if( $botcheck == '' ) {

			$mail->SetFrom( $email , $name );
			$mail->AddReplyTo( $email , $name );
			foreach( $toemails as $toemail ) {
				$mail->AddAddress( $toemail['email'] , $toemail['name'] );
			}
			$mail->Subject = $subject;

			$name = isset($name) ? "Name: $name

" : '';
			$email = isset($email) ? "Email: $email

" : '';
			$phone = isset($phone) ? "Phone: $phone

" : '';
			$website = isset($website) ? "Website URL: $website

" : '';
			$subject = isset($subject) ? "Subject: $subject

" : '';
			$message = isset($message) ? "Message: $message

" : '';

			$referrer = $_SERVER['HTTP_REFERER'] ? '

This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';

			$body = "$name $email $phone $website $subject $message $referrer";

			// Runs only when File Field is present in the Contact Form
			if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
				$mail->IsHTML(true);
				$mail->AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
			}

			// Runs only when reCaptcha is present in the Contact Form
			if( isset( $_POST['g-recaptcha-response'] ) ) {
				$recaptcha_response = $_POST['g-recaptcha-response'];
				$response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );

				$g_response = json_decode( $response );

				if ( $g_response->success !== true ) {
					echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
					die;
				}
			}

			$mail->MsgHTML( $body );
			$sendEmail = $mail->Send();

			if( $sendEmail == true ):
				echo '{ "alert": "success", "message": "' . $message_success . '" }';
			else:
				echo '{ "alert": "error", "message": "Email **could not** be sent due to some Unexpected Error. Please Try Again later.

**Reason:**
' . $mail->ErrorInfo . '" }';
			endif;
		} else {
			echo '{ "alert": "error", "message": "Bot **Detected**.! Clean yourself Botster.!" }';
		}
	} else {
		echo '{ "alert": "error", "message": "Please **Fill up** all the Fields and Try Again." }';
	}
} else {
	echo '{ "alert": "error", "message": "An **unexpected error** occured. Please Try Again later." }';
}

?>
SSemicolon WebSTAFFJan 20, 2017

Hello,

Apologies about the Delays in replying! We have just checked out your Website and it appears to be working fine at the moment. Please let us know if you are facing any further issues with this. Thanks for your Patience.

Do let us know if we can help you with anything else or if you find any further issues with Canvas.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard