John Davidson

php - My POST form is not passing data I get no error message and I am just redirected to the next page without the data being processed

0 comments
Message:


I have a login form:


<!--SIGNUP = modal_form.php-->
<!--Modal start-->
<div class="modal fade" id="enroll" tabindex="-1" aria-labelledby="enrollLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="enrollLabel">User signup</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>

<div class="modal-body">
<p class="lead">Fill out this form we will get back to you</p>
<!-- Form -->
<form id="signup-form" class="form" method="POST" action="./includes/signup.inc.php">
<?php
$fullUrl = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";


if (strpos($fullUrl, "error=empty_input") == true) {
echo "<div class='alert alert-danger alert-dismissible fade show' role='alert'>
<strong>Holy guacamole!</strong> You should fill in on some of those fields below.
<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button>
</div>";
.
.
.
.
.

<strong>Success!</strong> Success you signed up.
<button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button>
</div>";
} else {
unset($_SESSION['error1']);
}
?>

<div class="mb-3 input-control">
<label for="full-name">Full name\User name</label><br>
<p>*You can only have on user name per e-mail account</p>
<input type="text" class="form-control" id="full-name" name="full-name"
placeholder="John Smith">
<small class="message" id="message-full-name"></small>
<br>
</div>
<div class="mb-3 input-control">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email"
placeholder="[email protected]">
<small class="message" id="message-email"></small>
<br>
</div>

<div class="mb-3 input-control">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password"
placeholder="Password">
<small class="message" id="message-password"></small>
<br>
</div>

<div class="mb-3 input-control">
<label for="pwdRepeat">Password repeat</label>
<input type="password" class="form-control" id="pwdRepeat" name="pwdRepeat"
placeholder="Retype Password">
<small class="message" id="message-pwdRepeat"></small>
<br>
</div>

<a href="./includes/reset-password-form.php">Forgot your password?</a>

<div class="modal-footer">
<button type="reset" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" id="login-submit" class="btn btn-primary" name="submit">Register now</button>
</div>

<script src="./js/signup_error_handler.js"></script>

</form>
</div>
</div>
</div>
</div>



For some reason it doesn't send any data to the page login.inc.php it opens that page and doesn't do anything. When i var_dump() POST it shows array() if I do the same to the input fields as in I the POST values I get null eventhough the form was filled with some value.


And this is the page to which the data is sent to:


<?php

if (isset($_POST['login-submit'])) {
//Uzimamo podatke
$email = $_POST["login-email"];
$password = $_POST["login-password"];

//Instanciranje klase SignupContr
include "../classes/dbh.classes.php";
include "../classes/login.classes.php";
include "../classes/login-contr.classes.php";

$signup = new LoginContr($email, $password);

//Running error handlers and using signup

$signup->loginUser();

//Povratak na glavnu stranu

header("location: ../index.php?error=none");
}

The $signup variable is the class which has all of the functions which check the input values on the servers side and if somehow the input values where empty then the user would get a message that the inputed values are empty however this message doesn't appear. When i click the login-submit button I am taken to the empty login.inc.php page and nothing happens.



My Answer:











In your process.php file, make sure you are accessing the form data using the $_POST superglobal array. Here is an example of how you can retrieve the data from the form:
php


Make sure that the action attribute in your form tag matches the filename of your PHP script that is processing the form data. Also, check for any typos in your form field names and make sure that the form method is set to "post".

Rate this post

5 of 5 based on 3565 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us