Combination: Open mailto and form submit - forms

This combination of an open mailto window with a post form to test.php on one click does not work. Any suggestions?
<form id="myForm" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
<a href="mailto:..."
onclick="document.getElementById('myForm').submit();">
Submit
</a>
</form>

Check below solution to ignore href attribute and focus on using onclick only to do what you need
function submit() {
window.open('mailto:mail#example.org', '_blank');
document.getElementById('myForm').submit();
return true;
}
<form id="myForm" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
<a href="#" onclick="return submit();">
Submit
</a>
</form>
And if you need to use both href and onclick check below alternative solution
function submit() {
document.getElementById('myForm').submit();
return true;
}
<form id="myForm" action="test.php" method="post" onsubmit="alert('Ok')">
<input type="hidden" name="someName" value="helloworld" />
<a href="mailto:mail#example.org" target="_blank" onclick="return submit();">
Submit
</a>
</form>

#Wael: Thanks. The second solution is equivalent to this.
<form id="myForm2" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
Submit 2
</form>
The missing target attribute was the issue.
In Firefox it works as required. In Chrome it leads to
1. Opens the mail client
2. Posts to test.php
3. Opens a new browser tab with url mailto:mail#example.org (and focus)
With your first solution it is the same. How to avoid 3.?

Related

How to send data in form secretly

I want send hidden data with form.
my code is:
` <form action="my address" method="post">
<div>
<label for="title">Post title:</label>
<input type="text" id="title" name="title" value="My excellent blog post" />
</div>
<div>
<label for="content">Post content:</label>
<textarea id="content" name="content" cols="60" rows="5">
This is the content of my excellent blog post. I hope you enjoy it!
</textarea>
</div>
<div>
<button type="submit">Update post</button>
</div>
<input type="hidden" name="seckey" value="34657" />
</form> `
I use hidden input, but is not safe.
I want to send "seckey" secretly in a way ,that is not available in any way and anybody not access it. Completely safe
but if I use hidden input, the "seckey" is visible in the source page or inspect element in browser.
How to post the "seckey" in the form without it even being clear in the page source

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.

Posting problems with dynamical form using jquery

I wrote a dynamic form using jQuery, basically like this:
<form action="" method="post">
<input type="radio" name="rgroup" value="1">small form
<input type="radio" name="rgroup" value="2">whole form
<input type="text" name="inp1">
<div id="formpart">
<input type="text name="inp2">
</div
<input type="submit">
</form>
And
$('input[type=radio][name=rgroup]').change(function(){
$('#formpart').toggle();
});
Visually everything works fine, but in my $_POST array, the input field inp2 does appear, but is always empty... What can I do about it?

SEO Url not changing upon form submission

Am using SEO URls to load my pages ie http://www.mywebsite.com/p/page1/100 but am having a problem with my search form. When I click submit, instead of the entire url changing to the stated one in the form, it just appends the variables to the url eg http://www.mywebsite.com/p/page1/100?p=search&q=Any+Query+String+here.
My question is, how do I replace the entire URL with the form variable instead?
Here is my form code:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
OK I solved it using a hack I think???
Apparently if I append a variable to the action url, this will force the browser to load the new url instead of append the form variable to the existing url.
Eg.
<form action="<?php $_SERVER['PHP_SELF'] ?>?p=search" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
This worked for me but I dunno if it's the right way to achieve this or it's a hack.

Disable Firefox autocomplete?

For a reason I cannot determine, the password field is being populated when the form is submitted. This only happens in Firefox.
This is my form.
<form action="index.php/admin/settings/account" autocomplete="off" method="post">
<section>
<label for="email">Email</label>
<input type="text" name="email" value="test#test.com" autocomplete="off" />
</section>
<section>
<label for="password">Password</label>
<input type="password" name="password" value="******" autocomplete="off" />
</section>
<section>
<label for="confirm_password">Confirm Password</label>
<input type="password" name="confirm_password" value="******" />
</section>
<section>
<input type="submit" name="save" value="Save" />
</section>
</form>
<script>
console.log($('input[name="password"]').val());
$('form').submit(function(e) {
e.preventDefault();
console.log($('input[name="password"]').val());
});
</script>
As you can see. I have set the autocomplete="off" on both the form and the relevant fields. If I save the form without making changes. Autocomplete doesn't fire.
If I change the email address to an email with a saved password the password is changed when the form is submitted.
This is what I get in the console.
Firefox.
******
123123
Chrome
******
******
Has anyone come across this before? How do I stop this?
Is there a reason you're not setting autocomplete="off" in the confirm password section? It seems to be the only section that you're not explicitly disabling that property.