جلسه دوم
همانطور که جلسه پیش گفتیم قرار است کوتاه کننده ما آژاکس باشد. ما از کتابخانه jQuery و پلاگین jQuery Form استفاده می کنیم. قصد داریم تا از HTML5 هم برای طراحی فرم استفاده بکنم. فایل index.php را با آفتاب پرست خوشگلمان یعنی Notepad++ باز کنید و کد های زیر را قرار دهید:
<!DOCTYPE HTML>
<html dir="Rtl">
<head>
<title>Simple URL Shorter</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<meta name="Source" content="PersianScript.ir" />
<script type="text/javascript" src="//code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.form.js"></script
<script type="text/javascript" src="form.js"></script>
</head>
<body>
<div class="result" style="display:none"></div>
<form action="short.php" method="POST" id="short">
<label for="url">نشانی موردنظر خود را وارد کنید: </label><br /><input type="url" name="url" required="required" placeholder="مثال: http://www.persianscript.ir/" /><br />
<input type="submit" value="کوتاه کردن" name="exec" id="exec"/>
</form>
</body>
</html>
خب برای این که فرم ما زیباتر باشد، یک CSS هم برای فرم می نویسیم. دستورات CSS زیر در فایل style.css قرار دهید.
* {
margin:0;
padding:0;
}
html {
font:10pt "Tahoma",Arial,senf-serif;
direction:rtl;
background:#FFF;
text-shadow:1px 1px 1px #cacaca;
}
body {
margin:50px auto;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
padding:10px;
border:1px solid #c9c9c9;
width:450px;
}
form {
text-align:center;
}
input,select,textarea {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
font:10pt "Tahoma",Arial,senf-serif;
padding:5px;
margin-bottom:7px;
border:1px solid #cacaca;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
width:300px;
margin-top:4px;
}
input:hover,select:hover,textarea:hover {
border:1px solid #7613ae;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
input:focus,select:fous,textarea:focus {
border:1px solid #0096ff;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
input[type="url"]:focus {
direction:ltr;
}
input[type="submit"],button {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
font:10pt "Tahoma",Arial,senf-serif;
padding:5px;
border:1px solid #cacaca;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
background:#cacaca;
color:#FFF;
}
input[type="submit"]:hover,button:hover {
background:#7613ae;
border:1px solid #c9c9c9;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
input[type="submit"]::disable,button::disable{
background:#000;
border:1px solid #c9c9c9;
-webkit-transition: all 500ms ease;
-moz-transition: all 500ms ease;
-o-transition: all 500ms ease;
transition: all 500ms ease;
}
.result {
background:#7613ae;
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
color:white;
text-align:center;
padding:5px;
}
img {
border:none;
}
جلسه دوم هم به سلامتی تمام شد.
در جلسه بعد ما می خواهیم با jQuery Form کار کنیم تا فرممان را Ajax کنیم و بعد از آن وارد مسائل دیتابیس و کوتاه کردن لینک و نمایش آن بشویم.