HTML フォームが正しく送信されないという問題があります。私はフォームを初めて使用し、ログイン スクリプトを実行しようとしましたが、失敗しています。主にクロムを使用しています。これは、うまくいけば私の問題を示す非常に馬鹿げたコードです。このコードの何が問題なのかは、拡張コードにあると思います。これは私がログイン コーディングに使用した Web サイトです。主に参照用のログイン アカウント設定サイトです。
<?php
//this is here for testing
session_start();
//this shows
echo "something";
//none of these show
if(isset($_POST['submit'])){
echo "something";
echo "something";
echo "something";
echo "something";
}
if(isset($_POST['submit2'])){
echo "something";
echo "something";
echo "something";
echo "something";
}if(isset($_POST['submit3'])){
echo "something";
echo "something";
echo "something";
echo "something";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<footer>
<!-- I have tried it with and without an action -->
<form action="button_test.php" method="post" id="this" style="width: 100%; height: 100%; background-color: darkblue;">
<button type="submit" name="submit" id="submit" class="button" value="Submit">this is something</button>
<button type="button" name="submit2" id="submit2" class="button" value="this">this is something2</button>
<input type="button" name="submit3" id="submit3" class="button" value="true"/>
</form>
</footer>
</body>
</html>
最初のボタンは予想どおりページをリロードしますが、他のボタンは何もしません。これは、作業が必要な拡張メイン コードです。繰り返しますが、上記のコードはおそらく下のコードの問題点を説明していると思います。以下のコードは、主にコンテキストとより正確な回答を提供するためにあります。
<?php
//require once the DatabaseController.php file,
require_once 'Controllers/DatabaseController.php';
echo "this happend1";
// Creates a data connect object that creates a connection to
// a database
$connection = new DataConnect;
//Run the user_load function to set the user
$connection->user_load();
echo "this happend2";
/*
* Runs the in_loggedin function from a
* user object and checks if it is blank
*/
if($user->is_loggedin()!="")
{
echo "this happend3";
//return user to logged in home page if
//they are logged in
$user->redirect('index.php');
}
echo "this happend4";
/*
* THIS DOES NOT WORK FOR SOME REASON
*/
if(isset($_POST['btn-login']))
{
echo "this happend5";
//Load the variables with the new form data that has been executed
$uname = $_POST['txt_uname_email'];
$umail = $_POST['txt_uname_email'];
$upass = $_POST['txt_password'];
//If the user->login call is successful, go to home fully logged in
if($user->login($uname,$umail,$upass))
{
//Go to home, fully logged in
$user->redirect('index.php');
}
else
{
//Error
$error = "Wrong Details !";
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title> Josiah</title>
<link href="Assets/Stylesheets/styles-home.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
include_once 'header.php';
?>
<!-- recent blog post: contains the most recent blog post-->
<div id="main-content" class="content">
<div id="main-content-inner" class="inner-content">
<!-- this is the container for the form -->
<div class="form-container">
<!-- create a form that uses the "post" method which allows php to do $_POST on
corresponding variable names -->
<form method="post">
<h2>Sign in.</h2><hr />
<!-- checks if there was an error. If the error variable is set -->
<?php
if(isset($error))
{
?>
<!-- displays the error -->
<div class="alert alert-danger">
<i class="glyphicon glyphicon-warning-sign"></i> <?php echo $error; ?> !
</div>
<?php
}
?>
<!-- this is a form-group -->
<div class="form-group">
<!-- this is a text input. -->
<input type="text" class="form-control" name="txt_uname_email" placeholder="Username or E mail ID" required />
</div>
<!-- this is a form-group -->
<div class="form-group">
<!-- this is a text input. -->
<input type="password" class="form-control" name="txt_password" placeholder="Your Password" required />
</div>
<!-- splits parts of the form -->
<div class="clearfix"></div><hr />
<!-- this is a form group holdng the submit button -->
<div class="form-group">
<!-- the button interestingly has multiple classes -->
<button type="submit" name="btn-login" class="btn btn-block btn-primary">
<!-- splits parts of the form. Dont know specifically what this does. -->
<i class="glyphicon glyphicon-log-in"></i> SIGN IN
</button>
</div>
<br />
<label>Don't have account yet ! <a href="sign-up.php">Sign Up</a></label>
</form>
</div>
</div>
</div>
<!-- footer: contains social media, site map, and an up arrow-->
<?php
include 'footer.php'
?>
</body>
</html>