There is a registration page, looks like this:

<?php include("include/db_connect.php"); include("functions/functions.php"); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="ru"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="css/styles.css"> <link rel="stylesheet" href="trackbar/trackbar.css"> <link rel="stylesheet" href="css/reset.css"> <script type="text/javascript" src="/js/jquery-2.2.4.min.js"></script> <!--<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> --> <script type="text/javascript" src="/js/jcarousellite_1.0.1.js"></script> <script type="text/javascript" src="/js/shop-script.js"></script> <script type="text/javascript" src="/js/reg-val.js"></script> <script type="text/javascript" src="/js/jquery.cookie.min.js"></script> <script type="text/javascript" src="/trackbar/jquery.trackbar.js"></script> <script type="text/javascript" src="/js/jquery.form.js"></script> <script type="text/javascript" src="/js/jquery.validate.js"></script> <title>РСгистрация</title> </head> <body> <div id="block-body"> <!-- ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ шапки сайта --> <?php include("include/block-header.php"); ?> <!-- ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π±Π»ΠΎΠΊΠΎΠ² ΠΊΠ°Ρ‚Π΅Π³ΠΎΡ€ΠΈΠΉ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ², Ρ„ΠΈΠ»ΡŒΡ‚Ρ€Π° ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ΠΈ новостСй --> <div id="block-right"> <?php include("include/block-category.php"); include("include/block-parameter.php"); include("include/block-news.php"); ?> </div> <!-- Π‘Π»ΠΎΠΊ отобраТСния основного ΠΊΠΎΠ½Ρ‚Π΅Π½Ρ‚Π° сайта --> <div id="block-content"> <h2 class="h2-title">РСгистрация</h2> <form action="/reg/handler_reg.php" method="POST" id="form_reg"> <p id="reg_message"></p> <div id="block-form-registration"> <ul id="form-registration"> <li> <label for="">Π›ΠΎΠ³ΠΈΠ½</label> <span class="star">*</span> <input type="text" name="reg_login" id="reg_login"> </li> <li> <label for="">ΠŸΠ°Ρ€ΠΎΠ»ΡŒ</label> <span class="star">*</span> <input type="text" name="reg_pass" id="reg_pass"> <span id="genpass">Π‘Π³Π΅Π½Π΅Ρ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ</span> </li> <li> <label for="">Ѐамилия</label> <span class="star">*</span> <input type="text" name="reg_surname" id="reg_surname"> </li> <li> <label for="">Имя</label> <span class="star">*</span> <input type="text" name="reg_name" id="reg_name"> </li> <li> <label for="">ΠžΡ‚Ρ‡Π΅ΡΡ‚Π²ΠΎ</label> <span class="star">*</span> <input type="text" name="reg_patronymic" id="reg_patronymic"> </li> <li> <label for="">E-mail</label> <span class="star">*</span> <input type="text" name="reg_email" id="reg_email"> </li> <li> <label for="">ΠœΠΎΠ±ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½</label> <span class="star">*</span> <input type="text" name="reg_phone" id="reg_phone"> </li> <li> <label for="">АдрСс доставки</label> <span class="star">*</span> <input type="text" name="reg_address" id="reg_address"> </li> <li> <div id="block-captcha"> <img src="/reg/reg_captcha.php" alt="captcha"> <input type="text" name="reg_captcha" id="reg_captcha"> <p id="reloadcaptcha">ΠžΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ</p> </div> </li> </ul> </div> <p align="right"> <input type="submit" name="reg_submit" id="form_submit" value="РСгистрация"> </p> </form> </div> <!-- ΠŸΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Π½ΠΈΠΆΠ½Π΅ΠΉ части сайта --> <?php include("include/block-footer.php"); ?> </div> </body> </html> 

There is also a handler that enters the data from the registration form into the database:

 <?php if($_SERVER["REQUEST_METHOD"] == "POST") { session_start(); define('myeshop', true); include("../include/db_connect.php"); include("../functions/functions.php"); $error = array(); $login = iconv("UTF-8", "cp1251",strtolower(clearString($_POST['reg_login']))); $pass = iconv("UTF-8", "cp1251",strtolower(clearString($_POST['reg_pass']))); $surname = iconv("UTF-8", "cp1251",clearString($_POST['reg_surname'])); $name = iconv("UTF-8", "cp1251",clearString($_POST['reg_name'])); $patronymic = iconv("UTF-8", "cp1251",clearString($_POST['reg_patronymic'])); $email = iconv("UTF-8", "cp1251",clearString($_POST['reg_email'])); $phone = iconv("UTF-8", "cp1251",clearString($_POST['reg_phone'])); $address = iconv("UTF-8", "cp1251",clearString($_POST['reg_address'])); if (strlen($login) < 5 or strlen($login) > 15) { $error[] = "Π›ΠΎΠ³ΠΈΠ½ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ ΠΎΡ‚ 5 Π΄ΠΎ 15 символов!"; } else { $result = mysqli_query($link, "SELECT login FROM reg_user WHERE login = '$login'"); If (mysqli_num_rows($result) > 0) { $error[] = "Π›ΠΎΠ³ΠΈΠ½ занят!"; } } if (strlen($pass) < 7 or strlen($pass) > 15) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΏΠ°Ρ€ΠΎΠ»ΡŒ ΠΎΡ‚ 7 Π΄ΠΎ 15 символов!"; if (strlen($surname) < 3 or strlen($surname) > 20) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Ѐамилию ΠΎΡ‚ 3 Π΄ΠΎ 20 символов!"; if (strlen($name) < 3 or strlen($name) > 15) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Имя ΠΎΡ‚ 3 Π΄ΠΎ 15 символов!"; if (strlen($patronymic) < 3 or strlen($patronymic) > 25) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠžΡ‚Ρ‡Π΅ΡΡ‚Π²ΠΎ ΠΎΡ‚ 3 Π΄ΠΎ 25 символов!"; if (!preg_match("/^(?:[a-z0-9]+(?:[-_.]?[a-z0-9]+)?@[a-z0-9_.-]+(?:\.?[a-z0-9]+)?\.[az]{2,5})$/i",trim($email))) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½Ρ‹ΠΉ email!"; if (!$phone) $error[] = "Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π½ΠΎΠΌΠ΅Ρ€ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½Π°!"; if (!$address) $error[] = "НСобходимо ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ адрСс доставки!"; if($_SESSION['img_captcha'] != strtolower($_POST['reg_captcha'])) $error[] = "НСвСрный ΠΊΠΎΠ΄ с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ!"; unset($_SESSION['img_captcha']); if (count($error)) { echo implode('<br />',$error); }else { $pass = md5($pass); $pass = strrev($pass); $pass = "9nm2rv8q".$pass."2yo6z"; $ip = $_SERVER['REMOTE_ADDR']; mysqli_query($link, "INSERT INTO reg_user(login,password,surname,name,patronymic,email,phone,address,datetime,ip) VALUES( '".$login."', '".$pass."', '".$surname."', '".$name."', '".$patronymic."', '".$email."', '".$phone."', '".$address."', NOW(), '".$ip."' )"); echo true; } } ?> 

And there is a script in which data validation takes place, as well as the output of a notification by ajax that the registration was successful.

 $(document).ready(function() { $('#form_reg').validate( { // ΠΏΡ€Π°Π²ΠΈΠ»Π° для ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ rules:{ "reg_login":{ required:true, minlength:5, maxlength:15, remote: { type: "post", url: "/reg/check_login.php" } }, "reg_pass":{ required:true, minlength:7, maxlength:15 }, "reg_surname":{ required:true, minlength:3, maxlength:15 }, "reg_name":{ required:true, minlength:3, maxlength:15 }, "reg_patronymic":{ required:true, minlength:3, maxlength:25 }, "reg_email":{ required:true, email:true }, "reg_phone":{ required:true }, "reg_address":{ required:true }, "reg_captcha":{ required:true, remote: { type: "post", url: "/reg/check_captcha.php" } } }, // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌΡ‹Π΅ сообщСния ΠΏΡ€ΠΈ Π½Π°Ρ€ΡƒΡˆΠ΅Π½ΠΈΠΈ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΡ… ΠΏΡ€Π°Π²ΠΈΠ» messages:{ "reg_login":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π›ΠΎΠ³ΠΈΠ½!", minlength:"ΠžΡ‚ 5 Π΄ΠΎ 15 символов!", maxlength:"ΠžΡ‚ 5 Π΄ΠΎ 15 символов!", remote: "Π›ΠΎΠ³ΠΈΠ½ занят!" }, "reg_pass":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ ΠŸΠ°Ρ€ΠΎΠ»ΡŒ!", minlength:"ΠžΡ‚ 7 Π΄ΠΎ 15 символов!", maxlength:"ΠžΡ‚ 7 Π΄ΠΎ 15 символов!" }, "reg_surname":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π²Π°ΡˆΡƒ Ѐамилию!", minlength:"ΠžΡ‚ 3 Π΄ΠΎ 20 символов!", maxlength:"ΠžΡ‚ 3 Π΄ΠΎ 20 символов!" }, "reg_name":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ вашС Имя!", minlength:"ΠžΡ‚ 3 Π΄ΠΎ 15 символов!", maxlength:"ΠžΡ‚ 3 Π΄ΠΎ 15 символов!" }, "reg_patronymic":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ вашС ΠžΡ‚Ρ‡Π΅ΡΡ‚Π²ΠΎ!", minlength:"ΠžΡ‚ 3 Π΄ΠΎ 25 символов!", maxlength:"ΠžΡ‚ 3 Π΄ΠΎ 25 символов!" }, "reg_email":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ свой E-mail", email:"НС ΠΊΠΎΡ€Ρ€Π΅ΠΊΡ‚Π½Ρ‹ΠΉ E-mail" }, "reg_phone":{ required:"Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π½ΠΎΠΌΠ΅Ρ€ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½Π°!" }, "reg_address":{ required:"НСобходимо ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ адрСс доставки!" }, "reg_captcha":{ required:"Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΊΠΎΠ΄ с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ!", remote: "НС Π²Π΅Ρ€Π½Ρ‹ΠΉ ΠΊΠΎΠ΄ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ!" } }, submitHandler: function(form){ $(form).ajaxSubmit({ success: function(data) { if (data == true) { $("#block-form-registration").fadeOut(300,function() { $("#reg_message").addClass("reg_message_good").fadeIn(400).html("Π’Ρ‹ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ зарСгистрированы!"); $("#form_submit").hide(); }); } else { $("#reg_message").addClass("reg_message_error").fadeIn(400).html(data); } } }); } }); }); 

So, the script is connected (in the first listing you can see it, reg-val.js file), validation works fine, but when you click on the "registration" message, the agiax is not displayed, it only goes to the second listing file (handler_reg.php) and outputs to empty page number 1 ... In this case, the data from the form are successfully entered into the database !!! What could be the problem? I can't catch a mistake all day ...

  • Did you see errors in the console? Is a request being sent? - Alexandr Kiseloy
  • @E_p why do you think so? - Dremjke
  • I looked at the library, it looks like just api like this, ignore my comment. - E_p
  • @AlexandrKiseloy is empty in the console. If you comment out the function with ajax, then the same thing ... - Dremjke

2 answers 2

The problem may be that the function that is called when the button is pressed does not return false and in turn the standard submit html form is triggered.

submitHandler: function (form) {... return false; }

  • Can you please, please? - Dremjke
  • Alas, but everything is as before ... - Dremjke
  • Then I advise you to use a browser console or browser extension that shows http headers. This way you can determine at what point the redirect occurs. - Yakov Permyakov

Surprisingly, but it all worked by using Jquery version 1.8.2 ... For some other versions, including google and 2.2.4, which I used earlier, for some reason does not work ...