Quantcast
Channel: Topic Tag: contact-form | WordPress.org
Viewing all articles
Browse latest Browse all 6021

KA-Creative on "Javascript for adding Cookies to a Contact Form"

$
0
0

Hi, I am trying to add cookies to my pop-up forms at http://www.pharmasystemsusa.com but am having trouble getting it to work. I am very new to javascript, so I'm not sure if I'm doing this right or if I'm even close.

The website has several downloads that the client would like to collect contact information on, so every download has a pop-up form that requires the viewer to complete in order to receive the download. To improve the user experience, the client would like for the contact form to remember the viewer's information so that they only have to enter it once.

After some online research, I've applied the following code to my pop-up. Anyone have any ideas what I'm doing wrong here?

This particular pop-up can be found by clicking on the Rota Brochure on this page: http://pharmasystemsusa.com/pharma-equipment/select-by-machine-type/fill-finish-lines/rota-rotary-washers/

'<h1>DOWNLOAD ACCESS</h1>
Please complete the form below to access the ROTA Brochure:

<form action="http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf" method="POST">
<script type="text/javascript">var submitted=false;</script>
<iframe name="hidden_iframe" id="hidden_iframe" style="display:none;"
onload="if(submitted) {window.location='http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf';}"></iframe>
<form action="http://pharmasystemsusa.com/wp-content/uploads/2016/05/Rota-Brochure.pdf" method="post" target="hidden_iframe"
onsubmit="submitted=true;">

[contact-form to='myemail' subject='PharmaSystems Downloads - New Contact']
[contact-field label='First Name' type='name' name="usernameF" id="usernameF" required='1'/]
 [contact-field label='Last Name' type='text' name="usernameL" id="usernameL" required='1'/]
 [contact-field label='Company' type='text' name="company" id="company" required='1'/]
 [contact-field label='State / Province / Region' type='text' name="location" id="location" required='1'/]
 [contact-field label='Country' type='text' name="country" id="country" required='1'/]
 [contact-field label='Inquiry Status' type='select' required='1' options='Active Project,Just Browsing'/]
 [contact-field label='Email' type='email' name="email" id="email" required='1'/]
 [contact-field label='Phone' type='text' name="phone" id="phone" required='1'/][/contact-form]

<function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = firstname + "=" + value + "; " + expires;
document.cookie = lastname + "=" + value + "; " + expires;
document.cookie = company + "=" + value + "; " + expires;
document.cookie = location + "=" + value + "; " + expires;
document.cookie = country + "=" + value + "; " + expires;
document.cookie = email + "=" + value + "; " + expires;
document.cookie = phone + "=" + value + "; " + expires;
}

function getCookie(cname) {
var name = firstname + "=";
var name = lastname + "=";
var name = company + "=";
var name = location + "=";
var name = country + "=";
var name = email + "=";
var name = phone + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

function checkCookie() {
var user = getCookie("firstname");
var user = getCookie("lastname");
var user = getCookie("company");
var user = getCookie("location");
var user = getCookie("country");
var user = getCookie("email");
var user = getCookie("phone");
if (user != "") {
alert("Welcome again " + user);
} else {
user = prompt("Please enter your name:", "");
if (user != "" && user != null) {
setCookie("username", user, 365);
}
}
}

>
'


Viewing all articles
Browse latest Browse all 6021

Trending Articles