Basic HTML Link Send PHP Variable - php

This is my first go at trying to create a secure login feature.
Right now I have a mysql database storing a few usernames and passwords.
I also have a bootstrap template for a login page.
Here is some of the html:
<form>
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<a class="btn btn-primary btn-block" href="connect.php" method="post">Login</a>
</form>
I added the method and changed the action for the login button/link.
I would like to be able to click the login link and have the input values sent to an external php program connect.php shown below:
<!DOCTYPE html>
<html lang="en">
<body>
<div>
<?php
$user = $_POST["inputEmail"];
$pass = $_POST["inputPassword"];
echo "<h1>Hello: ".$user." also:".$pass"</h1>";
?>
</div>
</body>
</html>
Once I can get the values to send to the external script, I can then start to check the values against those in my database.
Solutions I have seen are mostly dealing with the form action and not a link. Those that are dealing with a link use get and hard code the values being sent rather than input.
EDIT 1:
I realized my html page was launching outside of my server. I made some changes to my html:
<form method="post">
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<a class="btn btn-primary btn-block" href="connect.php" method="post" name="submit">Login</a>
</form>
after these changes its telling me my inputs are Unidentified index's

SOLUTION
change submit link to submit button & make sure to run on a server
<form action="connect.php" method="POST">
<div class="form-group">
<div class="form-label-group">
<input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus">
<label for="inputEmail">Email address</label>
</div>
</div>
<div class="form-group">
<div class="form-label-group">
<input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required="required">
<label for="inputPassword">Password</label>
</div>
</div>
<button class="btn btn-primary btn-block" name="submit" type="submit">Login</button>
</form>

Related

Wordpress: PHP script cannot be find HTTP 404 ERROR

My current mission is to create a complete theme on WordPress. And to this is, a login system. Now, i've created the form and everything looks just fine, the problem is that wordpress is brawling with me and cannot locate my signup script, it creates a HTTP 404 error. Now I think that this has something to do with wordpress permalink system because it wants to find a page, instead of my signup.inc.php script.
Now this frustrates me because im kind of new to coding and I have no idea how to fix it!
Here is my code linking to the actual file located in a folder called 'includes'
<form action='includes/signup.inc.php' method="post">
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" name="uid" id="uid" placeholder="Username" required>
<small id="userhelp" class="form-text text-muted">This name will show on forums and the socialpage.</small>
</div>
<div class="form-group">
<label for="firstname">Firstname</label>
<input type="text" class="form-control" name="firstname" id="firstn" placeholder="Firstname" required>
</div>
<div class="form-group">
<label for="lastname">Lastname</label>
<input type="text" class="form-control" name="lastname" id="lastn" placeholder="Lastname" required>
</div>
<div class="form-group">
<label for="email">Email Adress</label>
<input type="email" class="form-control" name="mail" id="inputemail" aria-describedby="emailHelp" placeholder="Email" required>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="pwd" id="password" placeholder="Password" required>
</div>
<div class="form-group ">
<label for="password">Repeat password</label>
<input type="password" class="form-control" name="pwd-repeat" id="password" placeholder=" Repeat password" required>
<small id="passHelp" class="form-text text-muted">Please retype your password.</small>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="invalidCheck3" required>
<label class="form-check-label" for="invalidCheck3">Agree to terms and conditions</label>
<div class="invalid-feedback">
You must agree before submitting.
</div>
</div>
</div>
<button class="btn btn-dark" name="signup-submit" type="submit">Signup</button>
</form>
Please use this action in form:
<form action='<?php echo get_template_directory_uri(); ?>/includes/signup.inc.php' method="post">

form not sending data?

I cant for the life of me figure this out.
I have the following form which, when submitted, returns an empty array?
Its going to the right page when submitted (index.php) but its not passing anything as either GET or POST. Both return nothing using var_dump($_POST). Any ideas?
<form action="index.php" method="post">
<div class="form-group">
<label for="orderName">What is your name?</label>
<input type="textbox" class="form-control" id="orderName" aria-describedby="orderName" placeholder="Enter name">
</div>
<div class="form-group">
<label for="orderEmail">What is your email address?</label>
<input type="textbox" class="form-control" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email">
</div>
<div class="form-group">
<label for="orderCopies">How many copies of the book would you like?</label>
<input type="textbox" class="form-control" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books">
<small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small>
</div>
<div class="form-group">
<label for="orderAddress">Where would you like the book/s sent to?</label>
<textarea class="form-control" id="orderAddress" rows="3"></textarea>
</div>
<div class="form-group">
<label for="orderComments">Order comments</label>
<textarea class="form-control" id="orderComments" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Send order</button>
</form>
Input needs name attribute which is missing in your markup.
For example,
<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name">
Your code with name attributes on <input>, <textarea> and <button>:
<form action="index.php" method="post">
<div class="form-group">
<label for="orderName">What is your name?</label>
<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name">
</div>
<div class="form-group">
<label for="orderEmail">What is your email address?</label>
<input type="textbox" class="form-control" name="orderEmail" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email">
</div>
<div class="form-group">
<label for="orderCopies">How many copies of the book would you like?</label>
<input type="textbox" class="form-control" name="orderCopies" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books">
<small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small>
</div>
<div class="form-group">
<label for="orderAddress">Where would you like the book/s sent to?</label>
<textarea class="form-control" name="orderAddress" id="orderAddress" rows="3"></textarea>
</div>
<div class="form-group">
<label for="orderComments">Order comments</label>
<textarea class="form-control" name="orderComments" id="orderComments" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="submitButton">Send order</button>
</form>
You need to add name attribute tags for each input element. The name attribute and value gets sent via the post method to the script to receive it.
For each input tag always put the name attribute to pass the form data.
Ex.
<input type="textbox" class="form-control" id="orderName" name="orderName" aria-describedby="orderName" placeholder="Enter name">

I forgot how to capture a post in php

I am trying to capture the $_POST from this form:
<?php
var_dump($_POST);
?>
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
</div>
<div class="col-sm-6">
<input type="email" class="form-control input-lg" id="inputPassword3" placeholder="Email*">
</div>
</div>
<div class="form-group">
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Position">
</div>
<div class="col-sm-6">
<input type="text" class="form-control input-lg" id="inputPassword3" placeholder="Company">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<textarea class="form-control input-lg" rows="3" cols="10" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-6 col-sm-6">
<input type="submit" class="btn btn-default btn-lg btn-custom-sbmit" value="Send" />
</div>
</div>
</form>
and some how I keep failing because when I enter the details, and hit submit I get and array back: array(0) { }.
This is probably one of the most basic things, yet I forgot ow to do it. Ideas?
You have no name attributes for your <input> form elements. As a result nothing is sent to the server. You can verify this by using Firebug or Chrome's developer tools to see no data is sent.
<input type="text" class="form-control input-lg" id="inputEmail3" placeholder="Name*">
should be
<input type="text" class="form-control input-lg" name="inputEmail3" placeholder="Name*">
etc.

CodeIgniter Login with enter key

have this in my login form :
<div class="middle-box loginscreen animated fadeInDown">
<div>
<div>
<h1 class="logo-name"><?= $this->lang->line('GGG')?></h1>
</div>
<h3><?= $this->lang->line('GGG')?></h3>
<form class="m-t" role="form" action="welcome/check_user" id="check_user" method="POST">
<div id="save_result"></div>
<div class="form-group has-feedback">
<label class="control-label" for="username"><?= $this->lang->line('Username')?><sup class="mandatory">*</sup></label>
<input type="email" class="form-control required email" placeholder="<?= $this->lang->line('Username')?>" name="username" id="username" maxlength="50">
</div>
<div class="form-group has-feedback">
<label class="control-label" for="password"><?= $this->lang->line('Password')?><sup class="mandatory">*</sup></label>
<input type="password" id="btn" class="form-control required" placeholder="<?= $this->lang->line('Password')?>" name="password" id="password">
</div>
<button type="button" onclick="submit_form('#check_user')" class="btn btn-primary block full-width m-b"><?= $this->lang->line('Login')?></button>
need to get enter button to submit and it wont.
Change button type to submit instead of button - browsers would the submit the form on enter
<button type="submit" onclick="submit_form('#check_user')" class="btn btn-primary block full-width m-b"><?= $this->lang->line('Login')?></button>

HTML - form acting weird. Not redirecting to URL and using GET instead of POST

I'm a CS student and I have a DB project due in less than 24hrs! This is really annoying because I just need to forms to access my DB. Anyway, I have this form that works perfectly, while the second form does not work. Instead of posting and directing to the correct URL the second form re-loads the current page with the variables in the URL. Anybody have any ideas?
<form role="form" method="post" action="../controller/AddPerson.php">
<div class="box-body">
<div class="form-group">
<label for="newReservationFirstName"> First name</label>
<input type="text" class="form-control" name="newReservationFirstName" placeholder="Enter first name">
<label for="newReservationLastName"> Last name</label>
<input type="text" class="form-control" name="newReservationLastName" placeholder="Enter last name">
<label for="newReservationPhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newReservationPhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newReservationStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newReservationStreetAddress" placeholder="Enter street address">
<label for="newReservationCity"> City</label>
<input type="text" class="form-control" name="newReservationCity" placeholder="Enter city">
<label for="newReservationState"> State</label>
<select class="form-control" name="newReservationState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newReservationZip"> Zip Code</label>
<input type="text" class="form-control" name="newReservationZip" placeholder="Enter zipcode">
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Customer</button>
</div>
</form>
This is the form that doesn't work correctly, both pages exist on the server:
<form role="form" method="post" action="../controller/AddEmployee.php">
<div class="box-body">
<div class="form-group">
<label for="newEmployeeFirstName"> First name</label>
<input type="text" class="form-control" name="newEmployeeFirstName" placeholder="Enter first name">
<label for="newEmployeeLastName"> Last name</label>
<input type="text" class="form-control" name="newEmployeeLastName" placeholder="Enter last name">
<label for="newEmployeePhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newEmployeePhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newEmployeeStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newEmployeeStreetAddress" placeholder="Enter street address">
<label for="newEmployeeCity"> City</label>
<input type="text" class="form-control" name="newEmployeeCity" placeholder="Enter city">
<label for="newEmployeeState"> State</label>
<select class="form-control" name="newEmployeeState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newEmployeeZip"> Zip Code</label>
<input type="text" class="form-control" name="newEmployeeZip" placeholder="Enter zipcode">
<p></p>
<p></p>
<label for="newEmployeeFirstName"> Account Username</label>
<input type="text" class="form-control" name="newEmployeeUsername" placeholder="Enter username">
<label for="newEmployeeLastName"> Account Password</label>
<input type="text" class="form-control" name="newEmployeePassword" placeholder="Enter password">
<label for="newEmployeePhoneNumber"> Social Security Number</label>
<input type="text" class="form-control" name="newEmployeeSocial" placeholder="Enter SSN">
<div class="form-group" name="newEmployeePrivileges">
<br>
Privileges :
<select name="newEmployeePrivileges">
<option value="admin">Admin</option>
<option value="admin">Non-Admin</option>
</select>
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</div>
</div>
</form>
----------------------------------EDIT ----------------------------------------------
I tried making a another really simple form on some extra space and it still didn't work. I have no idea what could be cause it to do this.
<form method="post" action="post" action="../controller/AddEmployee.php">
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</form>
It could be that the button tag you are using to submit the form is causing it behave strangely. Try swapping out the button tag for an input. So:
<form method="post" enctype="multipart/form-data" action="../controller/AddEmployee.php">
<input type="submit" class="btn btn-success btn-lg" name="submit" >Add New Employee</input>
</form>
Also, I noticed you've included two 'action' attributes in your example form :-)

Categories