I already set the token in the form:
<form action="{{ route('user.store') }}" method="post">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<legend>Agregar nuevo usuario.</legend>
<div class="form-group">
<label>Código empresa</label>
<input type="number" class="form-control input-sm" name="enterprise" id="enterprise">
</div>
<div class="form-group">
<label>Nombre</label>
<input type="text" class="form-control input-sm" name="name" id="name">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control input-sm" name="email" id="email">
</div>
<div class="form-group">
<label>Usuario</label>
<input type="text" class="form-control input-sm" name="username" id="username">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control input-sm" name="password" id="password">
</div>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" name="create_content" id="create_content"> Crea contenido
</label>
<label class="checkbox-inline">
<input type="checkbox" name="active" id="active"> Activo
</label>
</div>
<button type="submit" class="btn btn-sm btn-primary" id="btn_Crear">Create</button>
</form>
Occasionally I'm receiving the TokenmismathException, and I'm not able to post anymore, If I comment out the line //'App\Http\Middleware\VerifyCsrfToken', in the Kernel.php file and try to post, it works, And if I uncomment the same line again 'App\Http\Middleware\VerifyCsrfToken',, now I don't receive the TokenmismatchException, until it stops working.
I'm not using ajax
Does anyone know why this is happening.
We had the exact same problem and never found a good solution. We did find a workaround although.
In your .env file, set the Session storage to Redis (yap, you have to install Redis on your server than). This worked for us, never encountered the same problem again.
Note, this works for us, but it of course is not a solution, merely a work-around until someone found the right solution.
Related
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">
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>
I am using HTML pages for UI purpose in laravel and when I try to login then it shows me an error page "TokenMismatchException in VerifyCsrfToken.php line 53:".
I am getting this error while login as well as registration.
I have the login.html page as follows:
<div class="container">
<form method="POST" action="login_display" accept-charset="UTF-8">
<h1>Login</h1>
<hr>
<div class="form-group">
<label for="email">Email ID :</label>
<input class="form-control" name="email" type="text" id="email" placeholder="Please enter email here">
</div>
<div class="form-group">
<label for="password">Password :</label>
<input class="form-control" name="password" type="password" value="" id="password" placeholder="Please enter password here">
</div>
<div class="form-group">
<input class="btn btn-primary form-control" type="submit" value="Login">
</div>
</form>
</div>
Try adding, <input type="hidden" name="_token" value="{{ csrf_token() }}"> to your form. Laravel uses this token to check that the form submission was valid.
I tried by adding following line to the form:
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
and this time it works well and I didn't get the TokenMismatchException error afterwards as well.
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.
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 :-)