Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Help with form validation

RoffDaniel pro asked 6 years ago


Hello. I have a problem with form validation because i don't know JS. So I'm asking for help.

Here's the code:

$data=$_POST;
 if(isset($data['do_login']))
 {
 $errors = array();
 if ($data['server'] != "" || isset($data['server']))
 {
 $user = R::findOne($data['server'], 'name = ?', array($data['name']));
 if( $user)
 {
 if(validate_password($data['password'], $user->password))
 {
 $_SESSION['logged_user'] = $user;
 header("Location: https://gov-helper.roffdaniel.com/");
 } else {
 $errors[] = 'Неверный пароль!';
 }
 } else
 {
 $errors[] = 'Аккаунт с таким логином не найден или не существует!';
 }
 } else
 {
 $errors[] = 'Выберете сервер авторизации!';
 }
 }



And form:




<form method="POST" action="https://gov-helper.roffdaniel.com/login/" id="jForm">
<div class="text-center">
<h3 class="dark-grey-text mb-5"><strong>Авторизация</strong></h3>
</div>';
if (!empty($errors)) {
echo'
<div class="card red lighten-1 text-center z-depth-2">
<div class="card-body">
<p class="white-text mb-0">'.array_shift($errors).'</p>
</div>
</div>
<hr class="my-5">
';
}echo'
<!--Body-->
<!--<label for="server" data-error="error">Сервер</label>-->
<select class="mdb-select colorful-select dropdown-primary" name="server" id="server">
<option value="" disabled selected>Выберите ваш сервер</option>
<option value="users_gov_orange">Orange</option>
<option value="users_gov_blue">Blue</option>
</select>

<div class="md-form">
<i class="fa fa-user prefix"></i>
<input type="text" id="name" name="name" class="form-control validate" value = "'.$data['name'].'">
<label for="name" data-error="error">Ваш ник</label>
</div>

<div class="md-form pb-3">
<i class="fa fa-lock prefix"></i>
<input type="password" id="password" name="password" class="form-control validate" value = "'.$data['password'].'">
<label for="password" data-error="error">Ваш пароль</label>

<!--<p class="font-small blue-text d-flex justify-content-end text-center"><a href="#" class="blue-text ml-1">восстановить пароль</a></p>-->
</div>

<div class="text-center mb-3">
<button type="submit" class="btn blue-gradient btn-block btn-rounded z-depth-1a" name="do_login" id="do_login">Войти</button>
</div>
</form>

Witold Tkaczyk free commented 6 years ago

Hi RoffDaniel, can you describe to me what exact problem do you have that I can find your problem? Any errors?

RoffDaniel pro commented 6 years ago

There are no errors. The question is, I don't know how to do validation because I don't know JS, and I'm asking you to try to do it for me, if you can.

Witold Tkaczyk free commented 6 years ago

You don't need to know js to do validation. Follow this or many others tutorials. https://www.sitepoint.com/form-validation-with-php/

RoffDaniel pro commented 6 years ago

Thank you, but still, how to make that at request in which there is an error, the page was not reloaded and the attribute "data-error" was called ?

Bartłomiej Malanowski staff commented 6 years ago

Create an AJAX request. In the response, you need to tell the script if the field is valid or invalid. If the field is invalid, you can simply add `.invalid` class to your input. You can also set the message by editing the label's attribute "data-error"

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Closed

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags