I have the following code for a simple registration page, called 'register.php':
<?php include('server.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>Registration system PHP and MySQL</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Register</h2>
</div>
<form method="post" action="register.php">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo $username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo $email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<button type="submit" class="btn" name="reg_user">Register</button>
</div>
<p>
Already a member? Sign in
</p>
</form>
</body>
</html>
Which is from a tutorial from this website: http://codewithawa.com/posts/complete-user-registration-system-using-php-and-mysql-database.
The problem I have is that whenever I click the "Register" button, I get a 404 Not found response page:
The registration form
The 404 Error Page
Yet the path to the resource in the URL is the same, and I can't seem to find anyone else with this issue elsewhere online. Is it an issue with PHPStorm?
The "register" button is a submit button. This means that when you click on the button the form will be sent (by POST method) to the page specified in the ACTION attribute of your form, in this case: register.php
If you get a 404 error page, this should mean that the page register.php does not exist.
Am I wrong?
It is simply telling you that you have either not loaded the "register.php" file, didn't load it into the proper directory or it is mis-spelled.
Create a php file using this, upload it to the same directory as your registration file, run it and post the results ::
<?php
$files = scandir(".", 1);
echo "<pre>";
print_r($files);
echo "</pre>";
?>
You should see something like this ::
Array
(
[0] => scandir.php
[1] => index.php
[2] => register.php
[3] => Core
[4] => ..
[5] => .
)
Related
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="header">
<H2>Login</H2>
</div>
<form method="post" action="https://..." enctype="multipart/form-data">
<?php include 'errors.php'; ?>
<div class="input-group">
<input type="text" name="username" placeholder="Username..." value="<?php echo $username; ?>">
</div>
<div class="input-group">
<input type="password" name="password_1" placeholder="Password...">
</div>
</div>
<div class="input-group">
<input type="file" name="image" placeholder="Image..." value="<?php echo $image; ?>"> // The File doesn't get echo in after submit and an error
</div>
<div class="input-group">
<button type="submit" name="login" class="btn">Login</button>
</div>
</form>
</body>
</html>
This Form is to register Users with an Image. After submit I check if there Name is all ready taken and look for other errors if there is an error I want that everything is still in the Form except the password. It is working with the Username but not with a file (Image). So how can I do that?
It is by default impossible to set a default value for a file picker due to security reasons
Learn more about it here
Others have explained why you can't do it. But if it is very important for you to achieve this behaviour (retaining all elements if there is an error in submission details), you can do this by setting up Ajax calls.
Since you would also add preventDefault() to the submit button event handler, the page won't be refreshed and the user won't lose entered data.
Your first ajax call will verify if entered data is valid. And then, if the response is positive, you send another ajax request to process the form submission.
im trying to create a custom page in WordPress i did some research and what you need to do is to create a .php file in the theme folder that include this code:
<?php /* Template Name: login */ ?>
this one php file that you include this cod in work great but in my case it's a registration form and it does have a link to another .php file which is register.php and when i try to go for that link it will say :"This page doesn't seem to exist" even though both .php files are in the same directory and i even tried to include full path in the link didn't work my full login.php file is like this:
<?php include('server.php') /* Template name: login*/ ?>
<!DOCTYPE html>
<html>
<head>
<title>login</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Login</h2>
</div>
<form method="post" action="login.php">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" >
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password">
</div>
<div class="input-group">
<button type="submit" class="btn" name="login_user">Login</button>
</div>
<p>
Not yet a member? Sign up<!-- problem is here -->
</p>
</form>
</body>
</html>
when i click on register it take me to :http://localhost/wordpress/login/register.php (login title of the page) and say it doesnt exist
instead of opening the register.php file in the same directory
I am writing code that is meant to log in users.
The login and search worked before but, ever since I combined the two the login form doesn't implement it's own code and instead, it runs the search code
EDIT: I found out why this happens, it's because I have been pressing enter instead of selecting login. So now I want to know, how do I press enter and implement the login code.
Below is the headerPublic.php which contains the search code
<?php
//---------------------BEGIN SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
if(isset($_POST["search_button"]))
{
//PHP SEARCH CODE
}
//---------------------END SEARCH FROM THE SEARCH BAR IN PUBLIC HEADER----------------------------------
?>
<html>
<head>
<title>VCR Exchange</title>
</head>
<body>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>Register</li>
<li>Log In</li>
</ul>
</nav>
And this is the login.php.
<?php require('connect.php'); ?>
<?php require('headerPublic.php'); ?>
<?php require('session.php'); ?>
<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="inputEmail" >Email address</label>
<input type="email" name="email" placeholder="Email address">
<label for="inputPassword" >Password</label>
<input type="password" name="password" placeholder="Password">
<button name="login" type="submit">Login</button>
</form>
</body>
</html>
<?php
// IF LOGIN BUTTON IS CLICKED:
if (isset($_POST['login']))
{
//LOG IN CODE
}
?>
The search form was missing a closing form tag
<!------------------------------------SEARCH BAR---------------------------------------------->
<li>
<form role="search" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<input type="search" name="search">
</div>
<button type="submit" value = "search" name="search_button">Search</button>
</form>
</li>
<!------------------------------------SEARCH BAR---------------------------------------------->
I have followed
How to Validate Google reCaptcha on Form Submit
I have below code in my index.php
<!DOCTYPE HTML>
<html>
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form method="post" action="post.php">
<div class="g-recaptcha" data-sitekey="6XXXXXXXXXXXXwdsf0K8HbXXXXXXX"></div>
<input type="submit" value="Submit" />
</form>
</body>
</html>
post.php
$response = $_REQUEST['g-recaptcha-response'];
$secret = '6XXXXXXXXXXXXwdsf0K8HbJNvMw-XXXX';
$server = $_SERVER['REMOTE_ADDR'];
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $response.'&remoteip='.$server);
$response = json_decode($response, true);
if ($response["success"] === true) {
echo "Logged In Successfully";
} else {
echo "You are a robot";
}
exit;
Above code is working fine.
How to do client side validation? It's not showing Captcha with Images Option.
I already done below
This is the standard behavior of the Recaptcha library does not display the first time the control over the images.
Try to view or post the page many times and you will see that the images not eventually appear.
If you want to do some client side validation on other additionnals fields, you must use jQuery or standar library like bootstrap or foundation, like this or this. You can see of full example of a working script here (inspired from bootstrap script and HTML 5 capabilities) :
This version of the script is the same all over Internet. No more client side validation for this ! Have a look to a reference : codepen.io signup
For example :
<!DOCTYPE HTML>
<html>
<head>
<link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form class="signin-form" method="post" action="post.php">
<!-- for example : Email and password validation (HTML 5) -->
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<!-- Site-key for automated tests -->
<div class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</body>
</html>
And here a sample code pen.
I have an html with submit button.
Submit sends you to php.
php code has this:
header("location:./setupOk.html");
$html = file_get_html('setupOk.html');
$ret = $html->find('div[id=valueOk]');
echo $ret[0]->innertext = "foo";
and this is some of my html setupOk.html code:
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
After executing button on first html, it goes to php and reloads my html website with setupOk but no text is innered to anywhere. Any solution?
EDIT:
my goal is to have a general html (with label and images) then from php, put text to that html and automatically load this html on user's browser
EDIT2:
MY FIRST HTML ISN'T THE SAME THAN 2ND HTML. FIRST ONE SENDS POST PETITION TO PHP THEN DEPENDING ON THE INFO SENT TO PHP, PHP WILL FILL TEXT TO THE 2ND HTML AND LOAD THIS LAST HTML ON USER'S BROWSER
Avoiding DOMParser and loading/redirecting to HTML page -- you can do it more simple way like (it has to be a PHP file):
<?php
$innerText = "";
if (!empty($_POST['Key'])) {
$innerText = "foo";
}
?>
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" value="<?php echo $innerText;?>"/>
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
If you think this is not what you want - please elaborate your need a bit.
UPDATE
setupOk.php
<form action="http://54.186.92.18/Pixel-Matrix/keys.php" method="post">
<div class="logo">
<link rel="stylesheet" type="text/css" href="styles.css">
<label id="logo"</label>
<!--<label for="name">Type:</label>-->
</div>
<div class="right">
<h1>Enter License Information</h1>
<div id="valueOk">
<input type="text" id="valOk" name="Key" readonly="readonly" />
</div>
</div>
<div class="button">
<button id="validateB" type="submit">Validate Now ></button>
</div>
</form>
keys.php [where you are submitting the form]
require_once('simple_html_dom.php');
$processedResult = "";
if (!empty($_POST['Key'])) {
$processedResult = "foo";
}
$html = file_get_html('setupOk.php');
$html->find('input[id=valOk]', 0)->value = $processedResult;
echo $html;
I have tested it and it's working.