/    Sign up×
Community /Pin to ProfileBookmark

so i’m trying to put a form emailer on my website, but i don’t want banner ads from a [i]free[/i] form hoster. So, knowing little about html & virtually nothing about javascript, i thought i’d go ahead and have a go 😮 by pasting together what i thought i’d need from: [URL=javascript.internet.com/]http://javascript.internet.com/[/URL]
perhaps unsurprisingly, it doesn’t seem to be working…

what i want it to do is email me the details, only allow the ‘website’ field to be unfilled and not allow multiple submissions. for now. i didn’t know what if anything the Script Size: bit at the bottom was for exactly, but seeing as i’d modified the original form a fair bit concluded that it must have changed. so i deleted it. is this a necessary bit of code & if so, how can i work out what it [i]should[/i] say?

Here it is for your amusement:

[CODE]<html>
<head>
<script language=”JavaScript”>

<!– This script and many more are available free online at –>
<!– The JavaScript Source!! http://javascript.internet.com –>

<!– Begin
var submitcount=0;

function reset() {
document.form.name.value=””;
document.form.email.value=””;
document.form.organisation.value=””;
document.form.name.value=””;
document.emailform.comments.value=””;
}

function checkFields() {
missinginfo = “”;
if (document.form.name.value == “”) {
missinginfo += “n – Name”;
}
if ((document.form.from.value == “”) ||
(document.form.from.value.indexOf(‘@’) == -1) ||
(document.form.from.value.indexOf(‘.’) == -1)) {
missinginfo += “n – Email address”;
if (document.form.organisation.value == “”) {
missinginfo += “n – Organisation”;
}
if(document.form.comments.value == “”) {
missinginfo += “n – Comments”;
}

if (missinginfo != “”) {
missinginfo =”_____________________________n” +
“You failed to correctly fill in your:n” +
missinginfo + “n_____________________________” +
“nPlease re-enter and submit again!”;
alert(missinginfo);
return false;
}

else
{
if (submitcount == 0)
{
submitcount++;
return true;
}
else
{
alert(“This form has already been submitted. Thanks!”);
return false;
}
}
}
// End –>
</script>
<title>w_a_accessform.html</title>
</head>
<body style=”background-color: rgb(0, 0, 0); color: rgb(0, 0, 0);”
alink=”#ee0000″ link=”#0000ee” vlink=”#551a8b”>
<form
style=”font-family: times new roman,times,serif; background-color: rgb(0, 0, 0);”
name=”form” onsubmit=”return checkFields();”> <input name=”to”
value=”[email protected]” type=”hidden”><input name=”subject”
value=”Password Application” type=”hidden”> <span
style=”color: rgb(204, 0, 0);”></span>
<h1 style=”text-align: center;”><small><span
style=”color: rgb(204, 0, 0);”>Please complete this form for a
password to access sample chapters &amp; work in progress.</span></small></h1>
<h2 style=”text-align: center;”><small><small><small><span
style=”color: rgb(204, 0, 0);”>N.B. All fields are required except
“Web Site”</span></small></small></small><br>
</h2>
<span style=”color: rgb(204, 0, 0);”>&nbsp;&nbsp;&nbsp;
Name:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span> <input name=”name” size=”30″
type=”text”><br>
<br>
<span style=”color: rgb(204, 0, 0);”> &nbsp;&nbsp;&nbsp; E-mail:</span>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <input name=”from” size=”30″
type=”text”><br>
<br>
<span style=”color: rgb(204, 0, 0);”>&nbsp;&nbsp;&nbsp; Organisation:
</span><input name=”organisation” size=”30″ type=”text”><br>
<br>
&nbsp;&nbsp;&nbsp; <span style=”color: rgb(204, 0, 0);”>Web Site:</span>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; <input name=”website” value=”http://” size=”30″
type=”text”><br>
<br>
<a><span style=”color: rgb(204, 0, 0);”>&nbsp;&nbsp;&nbsp; Why do you
want access to my work in progress?</span></a><br>
<br>
&nbsp;&nbsp;&nbsp;
<select name=”reason”>
<option selected=”selected”>I am/work for a Literary Agent &amp; may
be interested in representing your work. </option>
<option>I am/work for a Publisher &amp; may be interested in
publishing your work. </option>
<option>I am interested in obtaining a Copywrite License for your
work. </option>
<option>I wish to use your work as the basis for another type of
creative activity, but cannot afford to pay you right now. </option>
<option>I just want to read your work for free! </option>
</select>
<br>
<br>
<span style=”color: rgb(204, 0, 0);”>&nbsp;&nbsp;&nbsp; Comments:</span>
<br>
<br>
&nbsp;&nbsp;&nbsp;<textarea rows=”10″ cols=”90″ name=”comments”></textarea><br>
<br>
&nbsp;&nbsp;&nbsp;<input name=”submit” value=”Submit Form!”
type=”submit”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
value=” Cancel ” type=”reset”> <br>
<br>
</form>
<center
style=”font-family: times new roman,times,serif; background-color: rgb(0, 0, 0);”>
<font size=”-2″><span style=”color: rgb(204, 0, 0);”>Free JavaScripts
provided</span><br style=”color: rgb(204, 0, 0);”>
<span style=”color: rgb(204, 0, 0);”>by</span> <a
href=”http://javascriptsource.com”>The JavaScript Source</a></font>
</center>
</body>
</html>[/CODE]

it currently resides at: [URL=http://www.hostunlim.com/woodyamble/w_a_accessform.html]HostUnlim[/URL]
i am using mozilla 1.7.12 on mac os 10.1.3 and will be more than happy to plaster links to webdeveloper.com over all the pages of the finished site, assuming i get it working! thanx in advance, especially if you’ve just trawled through that lot (i didn’t know what might be relevant), woody.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KeveyOct 12.2005 — Here's a basic form, which you can use to compare to the validation script which follows. This form is made to interface with a basic mailer in perl, such as usually resides in your host's cgi-bin...generally a matt's script archive mailer (NOTE: it is not necessarily in the same folder as mine...have a look in your folders...it may not even be there...in which case you can get it at scriptarchives.com).

Also, regarding the statement:<input type=hidden name="formmail_mail_email" value="[email protected]">...the most common name I have seen for this hidden name is <input type=hidden name="recipient" value="[email protected]">

The redirect is not mandatory, but causes the perl script to redirect to your thank-you page vice its own...Not sure if this is exactly what you want, but I know it works well for me. Here's the form:

<form name="frm" action="/cgi-bin/formmail/FormMail.mail.pl" method="post" onsubmit="return validate(frm)">

<input type=hidden name="redirect" value="http://www.yoursite.com/thanks.html">

<input type=hidden name="formmail_mail_email" value="[email protected]">

<p>name:<br>

<input type="text" name="name">

<p>city:<br>

<input type="text" name="city">

<p>state:<br>

<input type="text" name="state">

<p>message:<br>

<textarea name="message"></textarea>

<p><input type="submit" name="submit" value="Submit">

<tr><td>&nbsp;</td>

</tr></table></form>


Here's the script I run for validation...the inputFields tell it what areas of the form have to be filled in. On my form they are called "name" ,"city" ,"state" and "message". If they fail to enter data in a required field they get a little pop up telling them to fill it in. You can add this script in right after the html above...

<script language="javascript">

function validate(frm) {

var inputFields = new Array("name" ,"city" ,"state" ,"message");

var counter;

var name;

var msg = "Please complete the following fields:n";

var badFields = "";

for (counter = 0; counter < inputFields.length; counter++) {

name = inputFields[counter];

if (frm.elements[name].value.length == 0) {

if (name == "formmail_mail_email") {

badFields = badFields + " - n";

} else {

badFields = badFields + " - " + name + "n";

}

}

}

if (badFields.length != 0) {

alert(msg + badFields);

return false;

}

return true;

}

</script>
Copy linkTweet thisAlerts:
@woodyambleauthorOct 12.2005 — This form is made to interface with a basic mailer in perl, such as usually resides in your host's cgi-bin...[/QUOTE] thanx, Kevey, but i'm afraid i don't understand what that means.

is perl anything to do with PHP? because HostUnlim (where my site is residing) doesn't allow PHP.

I've not actually messed about with what i got from

[URL=http://javascript.internet.com/]javascript.internet.com/[/URL]

very much. The bulk of the extra stuff in it is just colour/font/position that was generated by Mozilla and the rest is scripting from other examples from the same place.

I think there must be something pretty basic that i don't understand wrong but, having got it [i]looking[/i] the way i want it, i'd like to understand what's stopping it from working. i'm kind of hoping this will allow me to do other cool stuff with the site eventually. thanx again though, woody
Copy linkTweet thisAlerts:
@KeveyOct 12.2005 — Hi Woody,

If you were to paste the code I posted into a html file and upload to your server, you would see a form upon opening it in your browser (you can use your own form design) My example was just so you could see how they interrelate.

Here's the general flow of things:

After a person browses to your site: www.yoursite.com/form.html and fills out the form and clicks 'send', the validation script part of the form provided above validates the info to make sure that they filled out all the areas you specify. The form gets sent to your server which hopefully has a host-provided perl or cgi mail script that takes the info from the form and puts it into an email that is sent to the email address you identified in your form:

<input type=hidden name="[COLOR=DarkRed]recipient[/COLOR]" value="[COLOR=DarkRed][email protected][/COLOR]">.

Then, only if you want, the server will redirect the person to a thank-you page of your own design using this line in your form:

<input type=hidden name="redirect" value="[COLOR=DarkRed]http://www.yoursite.com/thanks.html[/COLOR]">

If you don't specify this then the perl/cgi will generate its own thank-you form which is very plain, and does not contain your branding without a bunch of modification...

So, for this to work in the way I specified you must have a FormMail script on your server. It can be found in your cgi-bin folder. If you FTP to your hosted space and do not see that folder then I am afraid you do not have the script to process the form and send the email. If you do not have the script you can contact your host and see what they say. You may just need a path to perl, or a path to cgi...ask the provider for this info and enter that path and filename they give you on this line of your script:

<form name="frm" action="[COLOR=DarkRed]/cgi-bin/formmail/FormMail.mail.pl[/COLOR]" method="post" onsubmit="return validate(frm)">

It doesn't have anything to do with PHP. It is generally available on most servers by default...but you could be the unlucky one.

So, here's what I would do:

1. Ask your host for the path to cgi/perl...usually called cgi-bin

2. Find out the FormMail file name on your server FormMail.mail.pl or something similar.

3. Enter this info in your form

4. Post your form and try it out.

5. Let me know if this helps. I am happy to assist as I just went through the exact same thing with my site.

There are many ways to do this...I just like this one personally...and believe it or not it is fairly easy to implement if you have all the information. If you cannot do it this way, please let us know what your host says you can do, and we can figure another method for you.

[COLOR=DarkRed]UPDATE: I just looked at your host and in the documentation they say they offer Email Scripts (cgiemail,formmail)...so you'll be good to go if you can get the info above![/COLOR]

Anyone else please chime in with your tidbits o' wisdom....
×

Success!

Help @woodyamble spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...