Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JavaScript Form Issue

Featured Replies

Hi for some reason my JavaScript is preventing me from receiving emails from my webform. I'm not great with Java Script can anyone see why im getting no email returned?

 

$('#contact-form').live('submit', function(event) {
	
		event.preventDefault();
		var sendemail = 1;
		
		$(this).find('input.mandatory,textarea.mandatory').each(function(){
			var fieldvalue = trim($(this).val());
			var errorfield = $(this).next('.error-message');
			
			if(fieldvalue == ''){
				$(this).addClass('error');
				errorfield.show();
				sendemail = 0;
			}else{
				if($(this).attr('name') == 'form-email'){
					var email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
					if(!email_regex.test(fieldvalue)){
						$(this).addClass('error');
						errorfield.show();
						sendemail = 0;
					} else {
						$(this).removeClass('error');
						errorfield.hide();
					}	
				} else {
					$(this).removeClass('error');
					errorfield.hide();
				}			
			}
			
		});
		
		if(sendemail != 0){
			var form = $(this);
			var name = $(this).find('[name=form-name]').val();
			var email = $(this).find('[name=form-email]').val();
			var message = $(this).find('[name=form-message]').val();
			var emailurl = $(this).attr('data-form-action');
			var confirmbox = $(this).find('.email-confirmation');
			var errorbox = $(this).find('.email-error');
	
			$.ajax({
				url: emailurl,
				data: $(form).serialize(),
				type: 'POST'
			})
			.done(function() { 
				confirmbox.fadeIn(500).delay(2500).fadeOut(500); 
				$('#contact-form input, #contact-form textarea').each(function(){
					$(this).val(''); 
				});
			})
			.fail(function() { errorbox.fadeIn(500).delay(5000).fadeOut(500); });
		}
		
	});
<form id="contact-form" method="post" action="email.php" class="text-left">
							
						<div class="email-confirmation hidden"><span class="glyphicons ok_2"><i></i></span> Email Success</div>
						<div class="email-error hidden"><span class="glyphicons remove_2"><i></i></span> Email Error</div>
						<input id="this_title"  class="hidden" type="text" name="this_title" value="" />
						<p>
							<label for="form-name">Name</label>
							<input type="text" class="mandatory" placeholder="Your name" id="form-name" name="form-name" value="">
							<span class="error-message hidden"><span class="glyphicons ban"><i></i></span> Missing Name</span>
						</p>
						<p>
							<label for="form-email">Email</label>
							<input type="text" class="mandatory" placeholder="Your email" id="form-email" name="form-email" value="">
							<span class="error-message hidden"><span class="glyphicons ban"><i></i></span> Missing or invalid Email</span>
						</p>
						<p>
							<label for="form-subject">Subject</label>
							<input type="text" placeholder="Email Subject" id="form-subject" name="form-subject" value="">
						</p>
						<p>
							<label for="form-message">Message</label>
							<textarea rows="6" class="mandatory" placeholder="Your message" id="form-message" name="form-message" ></textarea>
							<span class="error-message hidden"><span class="glyphicons ban"><i></i></span> Missing Mail Message</span>
						</p>
						<span class="clear"></span>
						<p>
							<button type="submit" class="btn btn-primary" name="form-submit">Submit</button>
						</p>
					
					</form>
<?php
// PHP email 
$this_form_spam = filter_input(INPUT_POST, 'this_title');

$name = filter_input(INPUT_POST, 'form-name');
$email = filter_input(INPUT_POST, 'form-email');
$subject = filter_input(INPUT_POST, 'form-subject'); if ($subject == '') {$subject = "Message from ZAIDMAN.COM contact form";}
$message = filter_input(INPUT_POST, 'form-message');

$from = 'FROM: Marc Zaidman Website Form';
$to = 'myemailaddress@yahoo.com';
$body = "FROM: $name \nEMAIL: $email \n\nMESSAGE: $message";

$sent = mail($to, $subject, $body, $from);

if ($this_form_spam != "") {
	// mock and laugh in the face of spam
	echo 'POSSIBLE SPAM EMAIL';
}

?>

 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.