Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI Forms and Javascript 1

Status
Not open for further replies.

richyd

MIS
Jan 4, 2002
82
GB
Hi All,

I'm pretty new to form scripting so I have a simple question to ask. I'm making a website that requires people to enter in information and submits it to the webmaster. How do I configure the button to mail the info back to the webmaster? is it just a simple form code that I need to add to a button or is it more than that?

Thanks
 

there is a simple mail script you can write a cgi for...it's called sendmail or formmail. what it does is you create a form, and on submission of the form you call the cgi script, it then parses out the forms info and sends an email to the webmaster, and returns the user to a regular 'thank you' html page or wherever you wish...no tacky mailto: or anything.

it does require a little scripting and work; but what doesn't!

- g
 
Thanks for that, Someone mentioned to me that I might need to run a cgi server or something like that. is this correct ?
I found this article on the web - is this the correct type of script that I'll need? i was hoping for something simpler. I just need one or two boxes with info to mail.


<HEAD>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function leaptoIntro() {
window.location=&quot;}
function About() {
alert(&quot;\nHave a suggestion for a JavaScript example?\n\nFill out the form and submit it. I will see what I can do.\n\nPlease be as specific as possible.&quot;);
document.forms[0].elements[1].focus();
}
function Reset() {
document.forms[0].elements[1].value = &quot;&quot;;
document.forms[0].elements[2].value = navigator.appName + &quot; &quot; + navigator.appVersion;
document.forms[0].elements[3].value = &quot;&quot;;
document.forms[0].elements[1].focus();
}
function submitForm() {
if ( (isName() ) && (isBrowser()) && (isSuggestion()) ) {
if (confirm(&quot;\nYour submission is about to be sent.\n\nClick YES to submit.\n\nClick NO to cancel.&quot;))
return true
else
return false;
}
else
return false;
}
function isName() {
var str = document.forms[0].elements[1].value;
if (str == &quot;&quot;) {
alert(&quot;\nThe NAME field is blank.\n\nPlease enter your name.&quot;)
document.forms[0].elements[1].focus();
return false;
}
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i + 1);
if (((ch < &quot;a&quot; || &quot;z&quot; < ch) && (ch < &quot;A&quot; || &quot;Z&quot; < ch)) && ch != ' ') {
alert(&quot;\nThe NAME field only accepts letters & spaces.\n\nPlease re-enter your name.&quot;);
document.forms[0].elements[1].select();
document.forms[0].elements[1].focus();
return false;
}
}
return true;
}
function isBrowser() {
if (document.forms[0].elements[2].value != navigator.appName + &quot; &quot; + navigator.appVersion) {
if (confirm(&quot;\nYou've changed your browser type.\n\nClick YES to keep changes.\n\nClick NO to restore detected browser.&quot;))
return true
else
{
document.forms[0].elements[2].value = navigator.appName + &quot; &quot; + navigator.appVersion;
return true;
}
}
else
return true;
}
function isSuggestion() {
var str = document.forms[0].elements[3].value;
if (str == &quot;&quot;) {
alert(&quot;\nThe SUGGESTION field is blank.\n\nPlease enter your suggestion.&quot;)
document.forms[0].elements[3].focus();
return false;
}
else
return true
}
// End -->
</SCRIPT>

<!-- STEP TWO: Add this onLoad event handler to the BODY tag -->

<BODY onLoad=&quot;Reset()&quot;>

<!-- STEP THREE: Copy this code into the BODY your HTML document -->

<CENTER>
<FORM ENCTYPE=&quot;text/plain&quot; NAME=&quot;test&quot; METHOD='POST' ACTION='mailto:you@yourdomain.com?subject=JS Suggestions' onSubmit=&quot;return submitForm()&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;form1&quot; VALUE=&quot;JS Suggestions&quot;>
<TABLE BORDER=0 WIDTH=564>
<TR>
<TD align=&quot;center&quot;> <FONT><STRONG>Enter your name:</STRONG></FONT>
<TD align=&quot;center&quot;> <FONT><STRONG>Browser/Version:</STRONG></FONT>
</TR>
<TR>
<TD align=&quot;center&quot;> <INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; SIZE=26 MAXLENGTH=40>
<TD align=&quot;center&quot;> <INPUT TYPE=&quot;text&quot; NAME=&quot;browser&quot; SIZE=26 MAXLENGTH=40>
</TR>
</TABLE>
<BR>
<TABLE BORDER=0>
<TR>
<TD align=&quot;center&quot;> <FONT><STRONG>Enter your suggestion(s):</STRONG></FONT>
</TR>
<TR>
<TD align=&quot;center&quot;><TEXTAREA NAME=&quot;suggestions&quot; ROWS=2 COLS=55 wrap=yes></TEXTAREA>
</TR>
</TABLE>
<BR><BR>
<TABLE BORDER=0 WIDTH=300>
<TR>
<TD align=&quot;center&quot;><INPUT TYPE=&quot;submit&quot; VALUE=&quot;Submit&quot;>
<TD align=&quot;center&quot;><INPUT TYPE=&quot;reset&quot; VALUE=&quot;Reset&quot; onClick=&quot;Reset()&quot;>
<TD align=&quot;center&quot;><INPUT TYPE=&quot;button&quot; VALUE=&quot;About&quot; onClick=&quot;About()&quot;>
<TD align=&quot;center&quot;><INPUT NAME=&quot;update&quot; TYPE=&quot;BUTTON&quot; VALUE=&quot;Close&quot; OnClick=&quot;leaptoIntro()&quot;>
</TR>
</TABLE>
</FORM>
</CENTER>

<p><center>
<font face=&quot;arial, helvetica&quot; size=&quot;-2&quot;>Free JavaScripts provided<br>
by <a href=&quot; JavaScript Source</a></font>
</center><p>

<!-- Script Size: 3.82 KB -->
 
yes, the above script will send an email. however, all the script does is call the email client the user has and then fills out the pertinent info and the user must send.

what i am talking about is using a cgi script and an html form.

see example here:


as you can see if you go there, the user types in whatever info required and then on submit, the info is sent to the webmaster and the script returns a 'thank you' page.

you just have to make sure the hosting company you use for your web site allows cgi...if so, you're good to go.

- spewn
 
thanks for your response. This is starting to make better sense now. I'll find out if my hosting site allows cgi.

Also do you know the command for allowing text to appear as '******' ? one of the forms requires a password box which I'm trying to set up.

Many thanks
 
Thanks very much, that worked fine. Does anybody know how I can submit text on a website without using cgi scripting?
 
Some ISP's will alow you to use a program called cgiemail. It's placed in your cgi-bin directory and you have to build a simple text script that sorta mirrors your web form. When the user fills out the form and submits it, an email is sent to whoever you choose and looks like the text script you built.

If you are getting a lot of hits then the process of handling all the data becomes a manual one with cgiemail. I'd opt for putting the form entries into a database that could be downloaded on a perodic basis and the data could be &quot;massaged&quot; programatically. There's always a better way...
 
I'm trying to get websurfers to enter comments on my webpage which forms are displayed. When they type text in to the form and click the submit button, their response ends up in an email to me or written in a text file somewhere I can access.
So basically I would like the users response in my mail box etc.

Tviman, have you got any examples on cgiemail? I've not come across this before

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top