I am having difficulty understanding why my application is sending an empty POST array upon form submission in my PHP MVC app.
I have the following code in my Register/Index view:
<form class="form-register" action="/register/checkregister" method="post">
<img src="/img/logo.png" class="logo">
<label for="name" class="sr-only">Name</label>
<input type="text" id="name" class="form-control" placeholder="Name" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="retypePassword" class="sr-only">Re-Type Password</label>
<input type="password" id="retypePassword" class="form-control" placeholder="Re-type Password" required>
<br>
<button class="btn btn-lg btn-success btn-block" type="submit">Register</button><br>
<a href="/login/index">Back to Login Page</a>
</form>
I was expecting this to give me access to the $_Post array from within my register/checkRegister method. However when I check the $_Post variable it shows that it has been submitted but with no values.
I am new to development in this way, if anyone could help with what I am doing wrong that would be great.
I tried to check within my checkRegister method in the Register controller by using this code:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo "<pre>";
var_dump($_POST);
echo "</pre>";
$user_name = Request::post('name');
echo 'user_name = '.$user_name . '<br><br>';
echo "POST";
}
But it returns an empty array for Post.
My code is on GitHub:
https://github.com/imoprojects/upbook
Thank you for any assistance,
Ian
you have not added the name attribute to your input tags add name attribute to every input tag like this
<form class="form-register" action="/register/checkregister" method="post">
<img src="/img/logo.png" class="logo">
<label for="name" class="sr-only">Name</label>
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email address" required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="retypePassword" class="sr-only">Re-Type Password</label>
<input type="password" name="retypePassword" id="retypePassword" class="form-control" placeholder="Re-type Password" required>
<br>
<button class="btn btn-lg btn-success btn-block" type="submit">Register</button><br>
<a href="/login/index">Back to Login Page</a>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.