Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. <input name=city"> и <input name="region">
  2.  
  3. <input name="city" autocomplete="off" data-kladr-type="city" data-kladr-
  4. id="7700000000000">
  5.  
  6. data-kladr-id="7700000000000"
  7.  
  8. <!doctype html>
  9. <html lang="ru">
  10. <head>
  11. <!-- КЛАДР -->
  12. <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  13. <link href="../themes/kladr/css/jquery.kladr.min.css" rel="stylesheet">
  14. <script src="../themes/kladr/js/jquery.kladr.min.js" type="text/javascript"></script>
  15. <script src="../themes/kladr/js/form.js" type="text/javascript"></script>
  16. <!-- КЛАДР -->
  17. </head>
  18. <body>
  19. <?php
  20. $host="localhost:3306";
  21. $user="root";
  22. $pass="hahin1991";
  23. $db_name="cachebank";
  24. $link=mysql_connect($host,$user,$pass);
  25. mysql_select_db($db_name,$link);
  26.  
  27. //Если переменная city передана
  28. if (isset($_POST["city"])) {
  29. //Вставляем данные, подставляя их в запрос
  30. $sql = mysql_query("INSERT INTO `city_region` (`city`, `region`)
  31. VALUES ('".$_POST['city']."','".$_POST['region']."')");
  32. //Если вставка прошла успешно
  33. if ($sql) {
  34. echo "<add>Данные успешно добавлены в таблицу.</add>";
  35. } else {
  36. echo "<error>Произошла ошибка.</error>";
  37. }
  38. }
  39. ?>
  40. <table>
  41. <div class="address">
  42. <h1>Форма для ввода адреса</h1>
  43. <form action="" method="post" class="js-form-address">
  44. <fieldset>
  45. <legend>Информация о проживание</legend>
  46. <div class="field">
  47. <label for="city">Город проживания </label>
  48. <input name="city">
  49. </div>
  50. <div class="field">
  51. <label for="region">Регион </label>
  52. <input name="region"><br>
  53. </div>
  54. </fieldset>
  55. <div class="tooltip" style="display: none;"><b></b><span></span></div>
  56. <input type="submit" value="Отправить Заявку">
  57. </form>
  58. </div>
  59. </table>
  60. <table><fieldset>
  61. <?php
  62. //Удаляем, если что
  63. if (isset($_GET['del'])) {
  64. $sql = mysql_query('DELETE FROM `city_region` WHERE `ID` = "'.$_GET['del'].'"');
  65. if ($sql) {
  66. echo "<ok>Товар удален.</ok>";
  67. } else {
  68. echo "<error>Произошла ошибка.</error>";
  69. }
  70. }
  71.  
  72.  
  73. //Получаем данные
  74. $sql = mysql_query('SELECT `ID`, `city`, `region` FROM `city_region`');
  75. while ($result = mysql_fetch_array($sql)) {
  76. echo "<div style='font-size: 16px;font-weight: 600;color: #795548;'> #";echo $result['ID']." ".$result['city']." ".$result['region']." - <a style='color: #0288d1;' href='?del=".$result['ID']."'>Удалить</a></div><br>";
  77. }
  78.  
  79. ?>
  80. </fieldset></table>
  81. </body>
  82.  
  83. $(function () {
  84. var
  85. $region = $('[name="region"]'),
  86. $city = $('[name="city"]');
  87.  
  88.  
  89. var $tooltip = $('.tooltip');
  90.  
  91. $.kladr.setDefault({
  92. parentInput: '.js-form-address',
  93. verify: true,
  94. select: function (obj) {
  95. setLabel($(this), obj.type);
  96. $tooltip.hide();
  97. },
  98. check: function (obj) {
  99. var $input = $(this);
  100.  
  101. if (obj) {
  102. setLabel($input, obj.type);
  103. $tooltip.hide();
  104. }
  105. else {
  106. showError($input, 'Введено неверно');
  107. }
  108. },
  109. checkBefore: function () {
  110. var $input = $(this);
  111.  
  112. if (!$.trim($input.val())) {
  113. $tooltip.hide();
  114. return false;
  115. }
  116. }
  117. });
  118. $region.kladr('type', $.kladr.type.region);
  119. $city.kladr('type', $.kladr.type.city);
  120.  
  121. function setLabel($input, text) {
  122. text = text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();
  123. $input.parent().find('label').text(text);
  124. }
  125.  
  126. function showError($input, message) {
  127. $tooltip.find('span').text(message);
  128.  
  129. var inputOffset = $input.offset(),
  130. inputWidth = $input.outerWidth(),
  131. inputHeight = $input.outerHeight();
  132.  
  133. var tooltipHeight = $tooltip.outerHeight();
  134.  
  135. $tooltip.css({
  136. left: (inputOffset.left + inputWidth + 10) + 'px',
  137. top: (inputOffset.top + (inputHeight - tooltipHeight) / 2 - 1) + 'px'
  138. });
  139.  
  140. $tooltip.show();
  141. }
  142. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement