smartwizard2-validation.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml"><head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <title>Smart Wizard 2 - Step Validation Example - a javascript jQuery wizard control plugin</title>
  5. <link href="styles/demo_style.css" rel="stylesheet" type="text/css">
  6. <link href="styles/smart_wizard.css" rel="stylesheet" type="text/css">
  7. <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
  8. <script type="text/javascript" src="js/jquery.smartWizard-2.0.min.js"></script>
  9. <script type="text/javascript">
  10. $(document).ready(function(){
  11. // Smart Wizard
  12. $('#wizard').smartWizard({transitionEffect:'slideleft',onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback,enableFinishButton:true});
  13. function leaveAStepCallback(obj){
  14. var step_num= obj.attr('rel');
  15. return validateSteps(step_num);
  16. }
  17. function onFinishCallback(){
  18. if(validateAllSteps()){
  19. $('form').submit();
  20. }
  21. }
  22. });
  23. function validateAllSteps(){
  24. var isStepValid = true;
  25. if(validateStep1() == false){
  26. isStepValid = false;
  27. $('#wizard').smartWizard('setError',{stepnum:1,iserror:true});
  28. }else{
  29. $('#wizard').smartWizard('setError',{stepnum:1,iserror:false});
  30. }
  31. if(validateStep3() == false){
  32. isStepValid = false;
  33. $('#wizard').smartWizard('setError',{stepnum:3,iserror:true});
  34. }else{
  35. $('#wizard').smartWizard('setError',{stepnum:3,iserror:false});
  36. }
  37. if(!isStepValid){
  38. $('#wizard').smartWizard('showMessage','Please correct the errors in the steps and continue');
  39. }
  40. return isStepValid;
  41. }
  42. function validateSteps(step){
  43. var isStepValid = true;
  44. // validate step 1
  45. if(step == 1){
  46. if(validateStep1() == false ){
  47. isStepValid = false;
  48. $('#wizard').smartWizard('showMessage','Please correct the errors in step'+step+ ' and click next.');
  49. $('#wizard').smartWizard('setError',{stepnum:step,iserror:true});
  50. }else{
  51. $('#wizard').smartWizard('setError',{stepnum:step,iserror:false});
  52. }
  53. }
  54. // validate step3
  55. if(step == 3){
  56. if(validateStep3() == false ){
  57. isStepValid = false;
  58. $('#wizard').smartWizard('showMessage','Please correct the errors in step'+step+ ' and click next.');
  59. $('#wizard').smartWizard('setError',{stepnum:step,iserror:true});
  60. }else{
  61. $('#wizard').smartWizard('setError',{stepnum:step,iserror:false});
  62. }
  63. }
  64. return isStepValid;
  65. }
  66. function validateStep1(){
  67. var isValid = true;
  68. // Validate Username
  69. var un = $('#username').val();
  70. if(!un && un.length <= 0){
  71. isValid = false;
  72. $('#msg_username').html('Please fill username').show();
  73. }else{
  74. $('#msg_username').html('').hide();
  75. }
  76. // validate password
  77. var pw = $('#password').val();
  78. if(!pw && pw.length <= 0){
  79. isValid = false;
  80. $('#msg_password').html('Please fill password').show();
  81. }else{
  82. $('#msg_password').html('').hide();
  83. }
  84. // validate confirm password
  85. var cpw = $('#cpassword').val();
  86. if(!cpw && cpw.length <= 0){
  87. isValid = false;
  88. $('#msg_cpassword').html('Please fill confirm password').show();
  89. }else{
  90. $('#msg_cpassword').html('').hide();
  91. }
  92. // validate password match
  93. if(pw && pw.length > 0 && cpw && cpw.length > 0){
  94. if(pw != cpw){
  95. isValid = false;
  96. $('#msg_cpassword').html('Password mismatch').show();
  97. }else{
  98. $('#msg_cpassword').html('').hide();
  99. }
  100. }
  101. return isValid;
  102. }
  103. function validateStep3(){
  104. var isValid = true;
  105. //validate email email
  106. var email = $('#email').val();
  107. if(email && email.length > 0){
  108. if(!isValidEmailAddress(email)){
  109. isValid = false;
  110. $('#msg_email').html('Email is invalid').show();
  111. }else{
  112. $('#msg_email').html('').hide();
  113. }
  114. }else{
  115. isValid = false;
  116. $('#msg_email').html('Please enter email').show();
  117. }
  118. return isValid;
  119. }
  120. // Email Validation
  121. function isValidEmailAddress(emailAddress) {
  122. var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  123. return pattern.test(emailAddress);
  124. }
  125. </script>
  126. </head><body>
  127. <div class="demoHead">
  128. <h2>Step Validation Example</h2>
  129. </div>
  130. <table align="center" border="0" cellpadding="0" cellspacing="0">
  131. <tr><td>
  132. <?
  133. if(isset($_REQUEST['issubmit'])){
  134. echo "<strong>form is sumbitted</strong>";
  135. }
  136. ?>
  137. <form action="#" method="POST">
  138. <input type='hidden' name="issubmit" value="1">
  139. <!-- Tabs -->
  140. <div id="wizard" class="swMain">
  141. <ul>
  142. <li><a href="#step-1">
  143. <label class="stepNumber">1</label>
  144. <span class="stepDesc">
  145. Account Details<br />
  146. <small>Fill your account details</small>
  147. </span>
  148. </a></li>
  149. <li><a href="#step-2">
  150. <label class="stepNumber">2</label>
  151. <span class="stepDesc">
  152. Profile Details<br />
  153. <small>Fill your profile details</small>
  154. </span>
  155. </a></li>
  156. <li><a href="#step-3">
  157. <label class="stepNumber">3</label>
  158. <span class="stepDesc">
  159. Contact Details<br />
  160. <small>Fill your contact details</small>
  161. </span>
  162. </a></li>
  163. <li><a href="#step-4">
  164. <label class="stepNumber">3</label>
  165. <span class="stepDesc">
  166. Other Details<br />
  167. <small>Fill your other details</small>
  168. </span>
  169. </a></li>
  170. </ul>
  171. <div id="step-1">
  172. <h2 class="StepTitle">Step 1: Account Details</h2>
  173. <table cellspacing="3" cellpadding="3" align="center">
  174. <tr>
  175. <td align="center" colspan="3">&nbsp;</td>
  176. </tr>
  177. <tr>
  178. <td align="right">Username :</td>
  179. <td align="left">
  180. <input type="text" id="username" name="username" value="" class="txtBox">
  181. </td>
  182. <td align="left"><span id="msg_username"></span>&nbsp;</td>
  183. </tr>
  184. <tr>
  185. <td align="right">Password :</td>
  186. <td align="left">
  187. <input type="password" id="password" name="password" value="" class="txtBox">
  188. </td>
  189. <td align="left"><span id="msg_password"></span>&nbsp;</td>
  190. </tr>
  191. <tr>
  192. <td align="right">Confirm Password :</td>
  193. <td align="left">
  194. <input type="password" id="cpassword" name="cpassword" value="" class="txtBox">
  195. </td>
  196. <td align="left"><span id="msg_cpassword"></span>&nbsp;</td>
  197. </tr>
  198. </table>
  199. </div>
  200. <div id="step-2">
  201. <h2 class="StepTitle">Step 2: Profile Details</h2>
  202. <table cellspacing="3" cellpadding="3" align="center">
  203. <tr>
  204. <td align="center" colspan="3">&nbsp;</td>
  205. </tr>
  206. <tr>
  207. <td align="right">First Name :</td>
  208. <td align="left">
  209. <input type="text" id="firstname" name="firstname" value="" class="txtBox">
  210. </td>
  211. <td align="left"><span id="msg_firstname"></span>&nbsp;</td>
  212. </tr>
  213. <tr>
  214. <td align="right">Last Name :</td>
  215. <td align="left">
  216. <input type="text" id="lastname" name="lastname" value="" class="txtBox">
  217. </td>
  218. <td align="left"><span id="msg_lastname"></span>&nbsp;</td>
  219. </tr>
  220. <tr>
  221. <td align="right">Gender :</td>
  222. <td align="left">
  223. <select id="gender" name="gender" class="txtBox">
  224. <option value="">-select-</option>
  225. <option value="Female">Female</option>
  226. <option value="Male">Male</option>
  227. </select>
  228. </td>
  229. <td align="left"><span id="msg_gender"></span>&nbsp;</td>
  230. </tr>
  231. </table>
  232. </div>
  233. <div id="step-3">
  234. <h2 class="StepTitle">Step 3: Contact Details</h2>
  235. <table cellspacing="3" cellpadding="3" align="center">
  236. <tr>
  237. <td align="center" colspan="3">&nbsp;</td>
  238. </tr>
  239. <tr>
  240. <td align="right">Email :</td>
  241. <td align="left">
  242. <input type="text" id="email" name="email" value="" class="txtBox">
  243. </td>
  244. <td align="left"><span id="msg_email"></span>&nbsp;</td>
  245. </tr>
  246. <tr>
  247. <td align="right">Phone :</td>
  248. <td align="left">
  249. <input type="text" id="phone" name="phone" value="" class="txtBox">
  250. </td>
  251. <td align="left"><span id="msg_phone"></span>&nbsp;</td>
  252. </tr>
  253. <tr>
  254. <td align="right">Address :</td>
  255. <td align="left">
  256. <textarea name="address" id="address" class="txtBox" rows="3"></textarea>
  257. </td>
  258. <td align="left"><span id="msg_address"></span>&nbsp;</td>
  259. </tr>
  260. </table>
  261. </div>
  262. <div id="step-4">
  263. <h2 class="StepTitle">Step 4: Other Details</h2>
  264. <table cellspacing="3" cellpadding="3" align="center">
  265. <tr>
  266. <td align="center" colspan="3">&nbsp;</td>
  267. </tr>
  268. <tr>
  269. <td align="right">Hobbies :</td>
  270. <td align="left">
  271. <input type="text" id="phone" name="phone" value="" class="txtBox">
  272. </td>
  273. <td align="left"><span id="msg_phone"></span>&nbsp;</td>
  274. </tr>
  275. <tr>
  276. <td align="right">About You :</td>
  277. <td align="left">
  278. <textarea name="address" id="address" class="txtBox" rows="5"></textarea>
  279. </td>
  280. <td align="left"><span id="msg_address"></span>&nbsp;</td>
  281. </tr>
  282. </table>
  283. </div>
  284. </div>
  285. <!-- End SmartWizard Content -->
  286. </form>
  287. </td></tr>
  288. </table>
  289. </body>
  290. </html>