I tried the solution at How do I add HTML form data to a mailto link
that did not work in my HTML5 snippet on mobile.
<!-- contact -->
<section id="section-contact" class="section appear clearfix">
<div class="container">
<div class="row mar-bot40">
<div class="col-md-offset-3 col-md-6">
<div class="section-header">
<h2 class="section-heading animated" data-animation="bounceInUp">Contact us</h2>
<p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet consectetur, adipisci velit, sed quia non numquam.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<form role="form" class="contactForm">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="tel" class="form-control" name="telephone" id="telephone" placeholder="111-111-1111" data-rule="email" data-msg="Please enter a valid telephone number" pattern="[0-9]{3}[0-9]{3}[0-9]{4}" required />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center">
<button type="submit" class="line-btn green" onclick="submitForm();return false;">Submit</button>
</div>
</form>
<script>
function submitForm(){
var name = document.getElementsByName("name")[0].value;
var email = document.getElementsByName("email")[0].value;
var phone = document.getElementsByName("telephone")[0].value;
var subject = document.getElementsByName("subject")[0].value;
var message = document.getElementsByName("message")[0].value;
window.open("mailto:denver.prophit#gmail.com?subject=" + encodeURIComponent(subject) +
"&body=Name:%20" + encodeURIComponent(name) +
"%0a%0aTelephone:%20" + encodeURIComponent(phone) +
"%0a%0a" + encodeURIComponent(message));
}
</script>
</div>
</div>
</div>
</section>
What I expected is the gmail app to open. What I got was a scroll back to the top of the page. Not sure what I missed after reading the questions from the previous question posted?
As highlighted by two of us in comments, your javascript is invalid, on this line...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name\n\n+Telephone:%20" + phone\ n\ n + message);
In particular the " + phone\ n\ n + message); part
The fixed version would be...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name\n\n+Telephone:%20" + phone + "\n\n" + message);
This would have been easily spotted by looking at the Console in your Developer Tools (press F12 on your browser) where it would have shown you that there is an error in the javascript.
Additionally the \n will not produce newlines in your email client, so you should use %0a (which is encoded \n) instead...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name%0a%0a+Telephone:%20" + phone + "%0a%0a" + message);
Originally I said use %0d which is the encoded \r... so if you wanted \r\n use %0d%0a
Finally, I believe there are a couple of other minor issues in that line, which will result in the incorrect values being passed through to the email client.
In particular the use of name and the +... and the fact that you're not URI encoding the values, meaning that if any of them have things like ? or & for example, it will mess up the link
This is what I believe you need...
window.open("mailto:example#gmail.com?subject=" + encodeURIComponent(subject) +
"&body=Name:%20" + encodeURIComponent(name) +
"%0a%0aTelephone:%20" + encodeURIComponent(phone) +
"%0a%0a" + encodeURIComponent(message));
I completely missed it, but I think the reason it's going back to the top of the page is that the button click is not being cancelled.
Update the onclick that calls the function to return false...
<button type="submit" class="line-btn green" onclick="submitForm();return false;">Submitx</button>
Related
I have a simple jQuery question. I have a Web App that looks like the following:
The HTML for the page is here:
<div id="hwAddition">
<div id="itemNumber" style="text-decoration: underline; font-size: large;">Item #</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="hwDescription" style="text-decoration: underline;">Description</label>
<form:textarea id="hwDescription" type="text"
class="form-control short" path="hwDescription"
name="hwDescription" placeholder="Description" maxlength="100"
rows="2" style="resize: none;" />
</div>
<div class="form-group col-md-4">
<label for="hwSerialNumber" style="text-decoration: underline;">Serial
#</label>
<form:input type="text" class="form-control" path="hwSerialNumber"
name="hwSerialNumber" placeholder="Serial #" maxlength="100" />
</div>
<div class="form-group col-md-4">
<label for="hwModelNumber" style="text-decoration: underline;">Model
#</label>
<form:input type="text" class="form-control" path="hwModelNumber"
name="hwModelNumber" placeholder="Model #" maxlength="100" />
</div>
</div>
<hr />
</div>
</div>
My issue lies with the "Item #" label. I'm trying to simply append a value after the markup so that the labels say "Item #1", "Item #2", and so on. The counting procedure is working and the jQuery is shown here:
var count = 1;
$(function() {
$("#hwAddition").attr('id', 'hwAddition' + count);
$("#itemNumber").attr('id', 'itemNumber' + count);
$("#itemNumber").append(count);
});
$('#hwAdditionButton').click(
function() {
var clonedObj = $("#hwAddition" + count).clone().attr('id', 'hwAddition' + (count+1));
clonedObj.find("#itemNumber" + count).attr('id', 'itemNumber' + (count+1));
clonedObj.insertAfter("#hwAddition" + count);
$("#itemNumber").append(count);
count++;
});
For some reason though, the .append() methods are adding nothing to the end of the labels. What am I doing incorrectly?
At the 5th and 12th rows, you do:
$("#itemNumber").append(count);
You're searching for #itemNumber without a "+ count", if I understand correctly you've changed both the original's and the clone's IDs to be itemNumber + count.
Also, the proper way to append text is:
$('#itemNumber' + count).append(document.createTextNode(count));
But why using append? in your case you can do:
$('#itemNumber' + count).text("Item #" + count);
The problem here it does not show the values of the message form, don't know that to do with this code. This was originally a javascript code but I converted it to typescript, I want to show the values in the outlook, but it does not show.
The code below is for HTML file
<div class="contact-section">
<img src="/assets/img-01.png">
<div class="inner-width">
<h1>Get in touch with us</h1>
<input type="text" class="name" placeholder="Your Name">
<input type="email" class="email" placeholder="Your Email">
<textarea rows="1" placeholder="Message" class="message"></textarea>
<a class="btn-submit" onmouseover="appendMailTo()" id="sendMail"
href="mailto:random12#gmail.com?Subject=Hello%20again" >Get in
touch </a>
</div>
The code below is for the ts file
appendMailTo(){
let message = (document.getElementById("message") as HTMLInputElement).value;
let subject = document.getElementById("mailSubject")
console.log(subject);
console.log(message);
let mailToAttr = document.getElementById("sendMail");
mailToAttr.setAttribute("href", "mailto:randoms12#gmail.com?
subject="+subject+"&body="+message);
}
For security purposes, Outlook blocks any scripts in message bodies. See Is JavaScript supported in an email message? for more information.
i have a form where every email is registered with #scoops.com but every time i have to enter #scoops.com i want that user just enter email name and #scoops.com auto fill and it will also show at the end of input field ? here it is my code
<div class="form-group" autocomplete="off">
<label>Email <span style="opacity: 0.5; font-style: italic;">(Required)</span></label>
<input autocomplete="nope" type="text" name="email" id="email" class="form-control input-lg"
placeholder="Enter Email" name="name" required=""/>
<span id="error_email"></span>
#if($errors->has('email'))
<div class="alert alert-danger">
{{ $errors->first('email') }}
</div>
#endif
</div>
i want something like this
Since you use Bootstrap: Try to wrap your mail input into an Inputgroup.
And then append the mail ending(by grouping your inputs). Also im not sure if 'autocomplete="nope"' is a state for this attribute. You should consider "off" if nope means no.
<div class="input-group">
<input autocomplete="off" type="text" name="email" id="email" class="form-control input-lg" placeholder="Enter Email" name="name" required=""/>
<div class="input-group-append">
<span class="input-group-text">#scoops.com</span>
</div>
</div>
Adding to what´s been said above, you can do something like the code below to submit the user-typed value appended with whatever text you want:
<input id="myInput">
<button onclick="submit(document.getElementById('myInput').value)"></button>
<script>
function submit(inputValue) {
const email = inputValue + "#scoops.com"
// insert here the code (like a POST request) to send the 'email' constant to wherever you want
}
</script>
I have a contact form at codepen.io, but it is not working. I don't know where I must put the email address that messages will be sent to.
<form class="cf">
<div class="half left cf">
<input type="text" id="input-name" placeholder="Name">
<input type="email" id="input-email" placeholder="Email address">
<input type="text" id="input-subject" placeholder="Subject">
</div>
<div class="half right cf">
<textarea name="message" type="text" id="input-message" placeholder="Message"></textarea>
</div>
<input type="submit" value="Submit" id="input-submit">
</form>
Thanks in advance for any help.
If you just want a really basic form to send an email, you can set the form action to "mailto:user#email.com". This will open the users default mail client and populate the subject and body with the contents of inputs named "subject" and "body" in the form. The form itself won't send email though - you would need PHP for that.
I am working on an MVC5 Web Application , I have a simple registration form containing Email , postcode and password. But when I register the chrome remembers the postcode and password rather than email and password; and next time when I try to enter email the postcodes appear as suggestions.
My markup for the form is as under:
I have edited the question and pasted the whole form. kindly suggest me what to do other than moving email and passwords up or down.
<div class="wrapper">
<div class="closeBetaWrapp">
<div class="simplePopup">
<div class="loginWrapp signupWrapp">
<div class="iconCont"><img src="images/orchaIcon.png" alt="Orcha"></div>
<form action="">
<div class="formrow ">
<div class="leftCol">
<label for="Email">Email</label>
<input class="formField" type="email" name="Email" id="Email" placeholder="Enter your email address here" />
</div>
<div class="leftCol">
<label for="Pcode">Postcode</label>
<input class="formField" type="tel" name="Pcode" id="Pcode" placeholder="Enter postcode here" />
</div>
<div class="leftCol">
<label>Year of Birth</label>
<select id="" class="dropdown">
<option>Choose your year of birth</option>
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
<option>1984</option>
<option>1985</option>
<option>1986</option>
<option>1987</option>
<option>1988</option>
<option>1989</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
</select>
</div>
<div class="leftCol">
<label>Gender</label>
<select id="" class="dropdown">
<option>Choose your year of birth</option>
<option>Female</option>
<option>Male</option>
</select>
</div>
<div class="leftCol">
<label for="Password">Password</label>
<input class="formField" type="password" name="Password" id="Password" placeholder="Enter your password here" />
</div>
<div class="rightCol">
<label for="CPassword">Confirm Password</label>
<input class="formField" type="password" name="CPassword" id="CPassword" placeholder="Enter password again" />
</div>
</div><!-- formrow -->
<div class="formrow">
<div class="rightCol btnCol">
<input class="moreBtn" type="submit" value="Signup" />
<input class="moreBtn cnclBtn" type="reset" value="Cancel" />
</div>
</div><!-- formrow -->
</form>
</div>
</div>
</div><!-- closeBetaWrapp -->
Browsers detect passwords by form.elements[n].type == "password" and iterating through all the document. Then it detects the username field by searching backwards through form elements for the text field immediately before the password field.
So, In your case, It thinks your postcode as your username field and remembers this.
So, solution is to move the postcode field above the email field.
If even after moving, it doesn't work, delete previously saved postcode-password value from 'saved passwords' in chrome settings. Also delete any previously saved values by using down arrow key to select the suggestion and pressing shift + delete.
I got the information about how browsers detect username-password field here & here
You can use the autocomplete attribute to tell the browser what the field contains. For example:
<input class="formField" autocomplete="postal-code" type="text" name="PostCode" id="PostCode" placeholder="Enter your postcode here" />
See https://html.spec.whatwg.org/multipage/forms.html#autofill for more information.