Permalink
Browse files

assignment-5 finished with few errors

  • Loading branch information...
1 parent b73f3ea commit bbf9e0f66a470fbb6b7a0f90f178d92a0380a75f @santhoshchris committed Jun 30, 2012
@@ -0,0 +1,25 @@
+<?php
+
+require_once 'includes/db.php';
+
+$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
+
+$sql = $db->prepare('
+ SELECT id
+ FROM users
+ WHERE email = :email
+
+ ');
+
+$sql->bindValue(':email', $email, PDO::PARAM_STR);
+$sql->execute();
+$results = $sql->fetch();
+
+if(empty($results)) {
+
+ echo 'available';
+
+} else {
+
+ echo 'unavailable';
+}
@@ -0,0 +1,26 @@
+<?php
+
+require_once 'includes/db.php';
+
+$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
+
+$sql = $db->prepare('
+ SELECT id
+ FROM users
+ WHERE username = :username
+
+ ');
+
+$sql->bindValue(':username', $username, PDO::PARAM_STR);
+$sql->execute();
+$results = $sql->fetch();
+
+
+if(empty($results)) {
+
+ echo 'available';
+
+} else {
+
+ echo 'unavailable';
+}
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Country</title>
+</head>
+
+<div id="CanadaProvince">
+ <label for="province">State</label>
+ <select>
+
+ <option value="G">Gujarath</option>
+ <option value="K">Kerala</option>
+ <option value="MH">Maharastra</option>
+ <option value="P">Pondicherry</option>
+ <option value="PUN">Punjab</option>
+ <option value="TN">Tamil Nadu</option>
+ <option value="UP">Uttar Pradesh</option>
+ <option value="WB">West Bengal</option>
+ <option value="JK">Jammu & Kashmir</option>
+
+</select>
+
+ <label for="postal-code">Postal Code</label>
+ <input id="postal-code" name="postal-code" required>
+
+<div id="CanadaProvince">
+
+ <label for="state">State</label>
+<select>
+
+ <option value="al">Alberta</option>
+ <option value="on">Ontario</option>
+ <option value="man">Manitoba</option>
+ <option value="nb">New Brunswick</option>
+ <option value="nf">Newfoundland</option>
+ <option value="ns">Nova Scotia</option>
+ <option value="nwt">North-West Territory</option>
+ <option value="pei">Prince Edward Island</option>
+ <option value="qu">Quebec</option>
+ <option value="sask">Sasketchewan</option>
+ <option value="yukon">Yukon</option>
+
+</select>
+ <div>
+ <label for="zip">Postal code</label>
+ <input id="zip" name="zip" required>
+ </div>
+</div>
+
+<body>
+</body>
+</html>
@@ -0,0 +1,50 @@
+.username-available:before {
+ font-size:30px;
+ content:"";
+}
+.email-available:before {
+ font-size:30px;
+ content:"";
+}
+
+
+
+#IndiaStates, #CanadaProvince {
+color:#F00;
+}
+
+
+[status="unchecked"] {
+ display:none;
+
+}
+
+
+[status="available"] {
+ color: #0C0;
+}
+
+[status="unavailable"] {
+ color: #F00;
+
+}
+
+[status="unavailable"]:before {
+ font-size:30px;
+ content:"×";
+ color: #F00;
+}
+
+
+.passwordrequirements li:before {
+ font-size:30px;
+ color: #F00;
+ content:"×";
+
+}
+
+.passwordrequirements li[data-state="achieved"]:before {
+ color: #0C0;
+ content:"";
+
+}
@@ -0,0 +1,9 @@
+<?php
+
+$user = getenv('DB_USER');
+$pass = getenv('DB_PASS');
+$data_source = getenv('DATA_SOURCE');
+
+$db = new PDO($data_source, $user, $pass);
+
+$db->exec('SET NAMES utf8');
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>JS - Form Validation</title>
+ <link href="css/general.css" rel="stylesheet">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="js/validator.js"></script>
+</head>
+<body>
+ <form>
+ <label for="username">Username:</label>
+
+ <input id="username" name="username" required>
+
+ <strong class="username-available" status="unchecked">Available</strong>
+
+ <p>
+
+ <label for="email">Email:</label>
+
+ <input id="email" name="email" required>
+
+ <strong class="email-available" status="unchecked">Available</strong>
+
+ <p>
+
+ <label for="password">Password:</label>
+
+ <input type="password" id="password" name="password" required>
+
+ <h4>Password Requirements:</h4>
+
+ <ul class="passwordrequirements">
+
+ <li class="pass-length">more than 6 characters</li>
+
+ <li class="pass-lower">1 lower case letter</li>
+
+ <li class="pass-upper">1 upper case letter</li>
+
+ <li class="pass-num">1 number</li>
+
+ <li class="pass-symbol">1 special character</li>
+
+ </ul>
+
+ <p>
+
+ <label for="city">City</label>
+ <input id="city" name="city" required>
+
+ <p>
+
+
+ <fieldset>
+ <legend>Country</legend>
+
+ <input type="radio" name="country" id="country" class="country" value="india">
+
+ <label for="india">India</label>
+
+ <input type="radio" name="country" id="country" class="country" value="canada">
+
+ <label for="canada">Canada</label>
+
+ </fieldset>
+
+ <div id="address"></div>
+
+ <button type="submit">SUBMIT</button>
+
+ </form>
@@ -0,0 +1,113 @@
+$(document).ready(function () {
+ var userAvailable = $('.username-available');
+ var emailAvailable = $('.email-available');
+ var passwordReqs = 0;
+
+ $("#username").on('change', function (ev) {
+ var username = $(this).val();
+
+ userAvailable.attr('status', 'unchecked');
+
+ if(username.length >= 5 && username.length <=12 ) {
+ var ajax = $.post('check-username.php', {
+ 'username' : username
+ });
+
+ ajax.done(function (data) {
+ if(data == 'available') {
+ userAvailable.attr('status', 'available').html('available');
+ } else {
+ userAvailable.attr('status', 'unavailable').html('Sorry Username unavailable :(');
+ }
+ });
+
+ } else {
+ userAvailable.attr('status', 'unavailable').html('Sorry Username unavailable :(');
+
+ }
+
+ });
+
+ $("#email").on('change', function (ev) {
+ var email = $(this).val();
+
+ emailAvailable.attr('status', 'unchecked');
+
+ if(email.length >= 5 && email.length <=30 ) {
+ var ajax = $.post('check-email.php', {
+ 'email' : email
+
+ });
+
+ ajax.done(function (data) {
+ if(data == 'available') {
+ emailAvailable.attr('status', 'available').html('available');
+ } else {
+ emailAvailable.attr('status', 'unavailable').html('Sorry this email is taken :(');
+ }
+ });
+
+ } else {
+ emailAvailable.attr('status', 'unavailable').html('Sorry this email is taken :(');
+
+ }
+
+ });
+
+
+ $("#password").on('keyup', function (ev) {
+ var password = $(this).val();
+
+ passwordReqs = 0;
+
+ if(password.length >5) {
+ passwordReqs++;
+ $('.pass-length').attr('data-state', 'achieved');
+
+ }
+
+ if(password.match(/[a-z]/)) {
+ passwordReqs++;
+ $('.pass-lower').attr('data-state', 'achieved');
+
+ }
+ if(password.match(/[A-Z]/)) {
+ passwordReqs++;
+ $('.pass-upper').attr('data-state', 'achieved');
+
+ }
+ if(password.match(/\d/)) {
+ passwordReqs++;
+ $('.pass-num').attr('data-state', 'achieved');
+
+ }
+ if(password.match(/[^a-zA-Z0-9]/)) {
+ passwordReqs++;
+ $('.pass-symbol').attr('data-state', 'achieved');
+
+ }
+
+ });
+
+ $('.country').on('click', function() {
+ var country = $(this);
+
+ if(country.val() == "canada") {
+ $('#address').load('country.html #CanadaProvince');
+ $('#IndiaStates').toggleClass('hidden');
+ }
+ if(country.val() == "india") {
+ $('#address').load('country.html #IndiaStates');
+ $('#CanadaProvince').toggleClass('hidden');
+ }
+
+ });
+
+ $('form').on('submit', function (ev) {
+ if(userAvailable.attr('status') =="unchecked"|| userAvailable.attr('status') == "unavailable"|| passwordReq < 5 ) {
+ ev.preventDefault();
+ }
+
+ });
+
+});

0 comments on commit bbf9e0f

Please sign in to comment.