<?php
//If the form is submitted
if(isset($_POST['submit'])) {

	//Check to make sure that the name field is not empty
	if(trim($_POST['contactname']) == '') {
		$hasError = true;
	} else {
		$name = trim($_POST['contactname']);
	}
	
	//Check to make sure that the telephone field is not empty
/*	if(trim($_POST['telephone']) == '') {
		//$hasError = false;
		$telephone = trim($_POST['telephone']);
	} else {
		$telephone = trim($_POST['telephone']);
	}
*/
	//Check to make sure that the subject field is not empty
	if(trim($_POST['subject']) == '') {
		//$hasError = true;
		$subject = trim($_POST['subject']);
	} else {
		$subject = trim($_POST['subject']);
	}

	//Check to make sure sure that a valid email address is submitted
	if(trim($_POST['email']) == '')  {
		$hasError = true;
	} //else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email'])))
		else  if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", trim($_POST['email']))){
		$hasError = true; 
	} else {
		$email = trim($_POST['email']);
	}

	//Check to make sure comments were entered
	if(trim($_POST['message']) == '') {
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$comments = stripslashes(trim($_POST['message']));
		} else {
			$comments = trim($_POST['message']);
		}
	}
	
	//Check to make sure that the subject field is not empty
/*	if(trim($_POST['kontaktiranje']) == '') {
		//$hasError = true;
		$droplist = trim($_POST['kontaktiranje']);
	} else {
		$droplist = trim($_POST['kontaktiranje']);
	}
*/

	//If there is no error, send the email
	if(!isset($hasError)) {
		$emailTo = 'udruga.bowlnd@gmail.com'; //Put your own email address here
		/*$emailTo2 = 'vedran.zivkovic@gmail.com'; //Put your second email address here*/
		$body = "Ime i prezime: $name \nNaslov: $subject \nEmail: $email \n\nPoruka:\n$comments";
		$headers = 'From: Poruka sa web stranice <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

		mail($emailTo, $subject, $body, $headers);
		/*mail($emailTo2, $subject, $body, $headers);*/
		$emailSent = true;
	}
}
?>

<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="shortcut icon" href="favicon.ico"/>
		
		<title>BOWLND</title>
		
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link href="assets/css/main.css" rel="stylesheet"/>
		<link href="assets/css/materialize.css" rel="stylesheet"/>
		<link href="assets/css/fontawesome-all.min.css" rel="stylesheet"/>
		<link href="assets/css/contact-form.css" rel="stylesheet"/>
		<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
		
		<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
		
		
		<script type="text/javascript" src="assets/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="assets/js/jquery-ui.min.js"></script>
		<script src="assets/js/jquery.validate.js" type="text/javascript"></script>
		<script type="text/javascript">
		$(document).ready(function(){
		$("#contactform").validate();
			});
	</script>
	</head>
	<body class="is-preload">
		<!-- Logotip -->
			<div id="logotip">
				<div id="logo">
				<a href="index.html"><img class="logotip" src="images/logo.png" width="100px" height="100px" alt=""/></a>
				</div>
				
				
				<div id="menu">
					<ul class="nav">
                        <li><a href="onama.html">O nama</a></li>
                        <li><a href="faq.html">Faq</a></li>
                    </ul>   
				</div>
			</div>
			
		<!-- Header -->
<header id="header">
	<div id="container" class="skrol100">
		<h2>POSTANI ČLAN</h2>
			<div id="forma">
					 <!--<?php if(isset($hasError)) { //If errors are found ?>
						<p class="error">Provjerite da li ste ispunili sva polja ispravno.</p>
					<?php } ?>-->

					<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
						<p class="centar">Poruka je uspiješno poslana!</p>
						<!--<p>Hvala <strong><?php echo $name;?></strong> što ste nam se javili! U što kraćem vremenu ćemo odgovoriti na Vašu poruku.</p>-->
					<?php } ?>
					
            <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform" class="customform">
				<div class="fontstyle input-polje"><input type="text" name="contactname" placeholder="Ime i Prezime" maxlength="50" size="" id="contactname" value="" class="required"></div>										   						
                <div class="fontstyle input-polje"><input type="text" name="subject" placeholder="Naslov" maxlength="50" size="" id="subject" value="" class="required"></div>										   						
                        
				<div class="fontstyle input-polje"><input type="email" name="email" placeholder="E-mail adresa" maxlength="50" size="" id="email" value="" class="required email"></div>
                        
				<div class="fontstyle input-polje"><textarea name="message" placeholder="Poruka" maxlength="5000" cols="" rows="6" id="message" class="required"></textarea></div>
                        
  				<div class="fontstyle input-polje"><input type="submit" name="submit" value="POŠALJI" class="submit_button"></div>
			</form>
            </div><!--/forma-->
			
			
			
	</div>
</header>

<!-- Footer -->
			<footer id="footer">
				<ul class="icons">
					<li><a href="https://www.instagram.com/bowlnd.hr/" class="icon brands fa-instagram" target="_blank"><span class="label">Instagram</span></a></li>
					<!--<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
					<li><a href="#" class="icon brands fa-instagram"><span class="label">Instagram</span></a></li>
					<li><a href="#" class="icon brands fa-github"><span class="label">GitHub</span></a></li>
					<li><a href="#" class="icon fa-envelope"><span class="label">Email</span></a></li>-->
				</ul>
				<ul class="copyright">
					<li style="color: #ff7518;">&copy; BOWLND &nbsp|&nbsp info: &nbsp udruga.bowlnd@gmail.com</li><li> <a href=""></a></li>
				</ul>
			</footer>
								
		
		<!-- Scripts -->
			<script src="assets/js/main.js"></script>
			<script src="assets/js/materialize.js"></script>
			<script src="assets/js/jquery.form.js"></script>
			<script src="assets/js/jquery.validate.min.js"></script>

	</body>
</html>