The page has expired due to inactivity - csrf

What's up guys!
I developed a system locally and it worked perfectly. When I put the system on the web server it started to give this error.
The page has expired due to inactivity.
I would not like to put the routes as an exception from csrf. One reason is that the system will be accessed by several people
The server has the required permissions on the storage folder.
My head:
<meta name="csrf-token" content="{{csrf_token()}}"/>
My form looks like this:
<form id="login" role="form" method="post" autocomplete="off" action="{{route('postLogar')}}">
{{csrf_field()}}
<div class="col-md-12">
<div class="row">
<div class="col-xs-6 col-md-6">
<input type="text" id="nr_cpf" name="nr_cpf" class="form-control input-lg"
value="" placeholder="CPF" maxlength="11" onBlur="validarCPF(this.value);" required/>
</div>
<div class="col-xs-6 col-md-6">
<input type="text" id="nr_matricula" name="nr_matricula" class="form-control input-lg"
value="" placeholder="MatrĂ­cula" maxlength="8" style="text-transform: capitalize" required/>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6 col-md-6">
<input type="password" id="ds_senha" name="ds_senha" class="form-control input-lg"
value="" placeholder="Senha" minlength='10' maxlength="10" required/>
</div>
<div class="col-xs-6 col-md-6">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-3 col-md-3">
</div>
<div class="col-xs-6 col-md-6">
<button class="btn btn-success btn-block btn-lg" type="submit">
Entrar
</button>
</div>
<div class="col-xs-3 col-md-3">
</div>
</div>
</div>
My route:
Route::post('/logar', 'ViewController#postLogar')->name('postLogar');
Session.php
'driver' => env('SESSION_DRIVER', 'file'),
'secure' => env('SESSION_SECURE_COOKIE', false),
'domain' => env('SESSION_DOMAIN', null),
I have other laravel systems running on that same web server and they all work normally.
I have no idea what may be happening.

Your laravel project directory might not have correct permissions to store the session stuff. Try giving correct permissons to these directories.
sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache
Navigate to your project root directory in Terminal / Command Promt and run these commands.

I discovered what was causing the problem on my system.
I Refined the Forms Request Part.
I used to do this before:
$nr_cpf = Input::get('nr_cpf_servidor');
I modified the code for this:
$nr_cpf = $request->nr_cpf;
Passing the request as object.
With this change ended up working my code. I do not know if the old form was giving conflict. But now it's working perfectly.

Related

Bad request 400 in Odoo contact form. Session expired('Invalid CSRF token')

I am facing an error in Odoo v 10 with the contact form, when I press the send button it gives an exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_http.py", line 195, in _dispatch
result = request.dispatch()
File "/usr/lib/python2.7/dist-packages/odoo/http.py", line 823, in dispatch
raise werkzeug.exceptions.BadRequest('Session expired (invalid CSRF token)')
BadRequest: 400: Bad Request
If I add the code to load the CSRF token suggested in an issue of their Github to the form:
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
It leads me to a new blank page showing the word false.
In the "Web layout" I have the next javascript code:
<script type="text/javascript">
var odoo = {
csrf_token: "<t t-esc="request.csrf_token(None)"/>",
};
</script>
I don't know if this code was manually added or it came with Odoo by default because this is an inherited installation.
The "Contact us" block is configured with the Send an Email action and a valid Recipient email, the Thank You Page works.
This is the final code after adding the block (without the CSRF hidden input):
<section class="as-contact-us" style="background-image: url(/theme_laze/static/src/img/our-work.jpg)">
<div class="container">
... Company description elements ...
<div class="col-md-8">
<form action="/website_form/crm.lead" method="post" data-model_name="mail.mail" data-success_page="/page/website_crm.contactus_thanks" class="s_website_form form-horizontal container-fluid mt32" enctype="multipart/form-data">
<div class="ascu-form">
<div class="row">
<div class="col-md-6">
<input class="form-control o_website_form_input" name="contact_name" required="" placeholder="Your Name*" type="text"/>
</div>
<div class="col-md-6">
<input class="form-control o_website_form_input" name="email_from" required="" placeholder="Your Email*" type="text"/>
</div>
</div>
<div class="row">
<div class="col-md-12">
<textarea class="form-control o_website_form_input" name="description" required="" placeholder="Message*"/>
</div>
<div class="col-md-12">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<button class="creative-btn1 o_default_snippet_text">Send</button>
</div>
</div>
</div>
<input class="form-field" name="email_to" value="to#email.org" type="hidden"/>
</form>
</div>
... Div closures ...
</div>
</section>
Does somebody know where is the problem?
I wouldn't like to deactivate the CSRF protection.
I'ts a routing issue! See code below for "csrf=False" and insert to solve question.
# /project/admin/post/{menu.name}/{submenu.name}/insert
#http.route(['/project/admin/post/<string:project>/<string:area>/insert'],type='http', auth='user', ***csrf=False***, website=True)
I was facing the same issue just enable the cookies in chrome it resolved my issue.
Enable cookies using.
Click on chrome Setting
Click Advance>> privacy and security
Click on Site Setting
Click Cookies and Site Data
Enable given.

Angular JS bindings seem to stop working inside of ng-include

I'm using angular js. When I have a snippet that I put in ng-include instead of outright writing the html to the same file, the former doesn't seem to pick up my bindings for my input fields.
In other words, if the following snippet:
<form name="pickupForm" ng-submit="completeCheckoutPickup()" novalidate>
<div class="row checkout-input">
<div class="col-sm-12">
<div class="title">
PICK UP DATE & TIME
</div>
<span class="glyphicon glyphicon-calendar date-icon-color"></span>
<input type="date" ng-model="userDate" required>
<span class="glyphicon glyphicon-time date-icon-color"></span>
<input type="time" ng-model="userTime" required>
</div>
</div>
</form>
is included as
<div ng-include src="'/templates/account/checkout/checkout.pickup.desktop.html'"></div>
The angularjs bindings for the ng-model stop working.
Any ideas?
enter code here

How to submit form data with Zurb Foundation

I'm a beginner trying to set up my first form with Zurb Foundation, and I'm not able to find in the documentation the info on how to actually pass the data. It's just a basic contact form with name/email/message that I'd like sent to my email once people click the Submit button... and I don't know how to do that.
I apologize for the simple question, your help is greatly appreciated.
Zurb foundation is front end frame work for website design and development , if you want to submit the form or do server communications, please read some basics,
HTML form and input : http://www.w3schools.com/html/html_forms.asp
Submitting HTML form using Jquery AJAX :
Submitting HTML form using Jquery AJAX
AJAX - Send a Request To a Server : http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
The HTML part:
<form action="form_contact_process.php" method="POST" name="contact" id="contact">
<fieldset>
<legend>Contact form</legend>
<div class="row collapse">
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div class="row collapse">
<label for="email">Email</label>
<input type="text" name="email" id="email">
</div>
<div class="row collapse">
<label for="phone">Phone</label>
<input type="text" name="phone" id="phone">
</div>
<div class="row collapse">
<label for="message">Message</label>
<textarea name="message" id="message" rows="5"></textarea>
</div>
<div class="row collapse">
<input class="button small large-12" type="submit" value="Submit">
</div>
</fieldset>
</form>
Then over at form_contact_process.php:
<?php
$name = $_POST['name'];
...
echo $name;

Do not understand form action right

This is the first time I've try to use a formulae to make a contact page on my site.
This is the code I use (and tried to adapt for my purposes):
<div id="main" class="content container bottom clearfix">
<div class="cont row">
<!-- FORM-->
<div class="form sevencol" style="width:52%">
<form action="mailto:contact#stefanseifert.com" id="contactForm" method="post">
<ul class="contactform">
<li><input type="text" name="contactName" id="contactName" value="" class="required requiredField"/>
<label for="contactName">Name</label>
</li>
<li>
<input type="text" name="email" id="email" value="" class="required requiredField email"/>
<label for="email">E-Mail</label>
</li>
<li class="textarea">
<textarea name="comments" id="commentsText" rows="10" cols="10" class=" required requiredField"></textarea>
</li>
<li>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6Lf-ueMSAAAAAExUbwjvdqnNuNjlkeN3_wQyl720"></script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6Lf-ueMSAAAAAExUbwjvdqnNuNjlkeN3_wQyl720" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
</li>
<li class="buttons"><br>
<input type="hidden" name="submitted" id="submitted" value="true"/>
<button type="submit" class="submit superlink">E-Mail senden</button>
</li>
</ul>
</form>
</div>
<!-- END FORM-->
</div>
The result of it, is that every time I test it my Email program opens and fills part of the code inside a new mail of mine.
What is wrong here?
What I wanted was that a mail with the content of the input fields is sent to me, instead!
Appreciate your help!
Thanks very much
Garavani
You can't send an email out of the browser.
<form action="mailto:contact#stefanseifert.com" ... specifies what should happen, once the form is submitted. This action opens the standard email client to send an email to that address - that's what you experienced.
if you want the email to be sent automatically by a server to you, you need to implement it in php, c#, java - or any other language on that server, and send the form data to the server

Is it possible to code a form over multiple divs?

I'm coding an email subscription form (api's proving a nightmare on their own) and I was wondering if it is possible to write a form across divs, as per below...
<div id="topsubscribe_label">STAY UP TO DATE, JOIN OUR MAILING LIST: </div>
<form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get">
<div id="subforminputs">
<input type="email" name="email" id="email" class="toptextinput" value="" placeholder="you#example.com"/><br />
</div>
<div id="topsubscribe_submit">
<input type="submit" id="topregisterButton" name="submit" class="textinput" value="Subscribe" />
</form>
</div>
Will this break the form? Is there another (simple) way to do this?
You can do this
<div>
<div>
<form>
</form>
</div>
</div>
You can also do this
<form>
<div>
</div>
<div>
</div>
</form>
But you cannot do this
<form>
<div>
</form>
</div>
Browser won't show any errors, you might have different output. Each browser handles these error diffrently.
This is acceptable:
<div>
<form>
<div><input /><input /></div>
<div><input /><input /></div>
</form>
</div>
This is not:
<div>
<form>
<input /><input />
</div>
<div>
<input /><input />
</form>
</div>
It may be worth noting that overlapping tags as in the 2nd example is invalid for all tags; not just form tags.
If you just want to group some fields, you can use fieldset element.