Php 7 way to submit forms
up vote
0
down vote
favorite
The following script submits a form. I want a more php 7/cleaner way to do the same exact thing. The functions are being passed in the object oriented User.php file.
How would a senior php developer refactor this code.
index.php
$username = htmlentities(trim($_POST['txt_username']));
$unpass = htmlentities(trim($_POST['txt_password']));
$password = password_hash($unpass, PASSWORD_BCRYPT, ['cost' => 12] );
$unemail = $_POST['txt_email'];
$email = filter_var($unemail, FILTER_VALIDATE_EMAIL);
if (isset($_POST['btn_signup']) ){
if($guest->check_user_exists($username)){
$errors= "Username Already Taken";
}
elseif(strlen($username) < 6){
$errors = "Username must be at least 6 characters";
}
elseif(strlen($unpass) < 6){
$errors = "Password must be at least 6 characters";
}
elseif($guest->check_email_exists($email)){
$errors= "Email Already Taken";
}
elseif($guest->signup($email,$password,$username)){
header("Location:index.php?registered");
die('didnt redirect');
}
else{
$errors= "Invalid Entry";
}
}
php
add a comment |
up vote
0
down vote
favorite
The following script submits a form. I want a more php 7/cleaner way to do the same exact thing. The functions are being passed in the object oriented User.php file.
How would a senior php developer refactor this code.
index.php
$username = htmlentities(trim($_POST['txt_username']));
$unpass = htmlentities(trim($_POST['txt_password']));
$password = password_hash($unpass, PASSWORD_BCRYPT, ['cost' => 12] );
$unemail = $_POST['txt_email'];
$email = filter_var($unemail, FILTER_VALIDATE_EMAIL);
if (isset($_POST['btn_signup']) ){
if($guest->check_user_exists($username)){
$errors= "Username Already Taken";
}
elseif(strlen($username) < 6){
$errors = "Username must be at least 6 characters";
}
elseif(strlen($unpass) < 6){
$errors = "Password must be at least 6 characters";
}
elseif($guest->check_email_exists($email)){
$errors= "Email Already Taken";
}
elseif($guest->signup($email,$password,$username)){
header("Location:index.php?registered");
die('didnt redirect');
}
else{
$errors= "Invalid Entry";
}
}
php
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The following script submits a form. I want a more php 7/cleaner way to do the same exact thing. The functions are being passed in the object oriented User.php file.
How would a senior php developer refactor this code.
index.php
$username = htmlentities(trim($_POST['txt_username']));
$unpass = htmlentities(trim($_POST['txt_password']));
$password = password_hash($unpass, PASSWORD_BCRYPT, ['cost' => 12] );
$unemail = $_POST['txt_email'];
$email = filter_var($unemail, FILTER_VALIDATE_EMAIL);
if (isset($_POST['btn_signup']) ){
if($guest->check_user_exists($username)){
$errors= "Username Already Taken";
}
elseif(strlen($username) < 6){
$errors = "Username must be at least 6 characters";
}
elseif(strlen($unpass) < 6){
$errors = "Password must be at least 6 characters";
}
elseif($guest->check_email_exists($email)){
$errors= "Email Already Taken";
}
elseif($guest->signup($email,$password,$username)){
header("Location:index.php?registered");
die('didnt redirect');
}
else{
$errors= "Invalid Entry";
}
}
php
The following script submits a form. I want a more php 7/cleaner way to do the same exact thing. The functions are being passed in the object oriented User.php file.
How would a senior php developer refactor this code.
index.php
$username = htmlentities(trim($_POST['txt_username']));
$unpass = htmlentities(trim($_POST['txt_password']));
$password = password_hash($unpass, PASSWORD_BCRYPT, ['cost' => 12] );
$unemail = $_POST['txt_email'];
$email = filter_var($unemail, FILTER_VALIDATE_EMAIL);
if (isset($_POST['btn_signup']) ){
if($guest->check_user_exists($username)){
$errors= "Username Already Taken";
}
elseif(strlen($username) < 6){
$errors = "Username must be at least 6 characters";
}
elseif(strlen($unpass) < 6){
$errors = "Password must be at least 6 characters";
}
elseif($guest->check_email_exists($email)){
$errors= "Email Already Taken";
}
elseif($guest->signup($email,$password,$username)){
header("Location:index.php?registered");
die('didnt redirect');
}
else{
$errors= "Invalid Entry";
}
}
php
php
asked 12 mins ago
BARNOWL
1625
1625
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208426%2fphp-7-way-to-submit-forms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown