crating a simple form

jeroengielen

Verified User
Joined
Sep 24, 2004
Messages
7
I tried allready 3 hours...
I know i must use CGI...
But can someone explain me how?
I want just that a visitor can send a mail from my site to me...

There must be 2 documents
1html and an other txt:

------------------------------------------
1:
<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="/cgi-bin/mail.cgi">
<input type="hidden" name="template"
value="/templates/formulier.txt">
<input type="hidden" name="send"
value=" http://www.i4s.be">
Naam: <input type="text" name="naam" value=""><br>
Email: <input type="text" name="email" value=""><br>
<input type="submit" name="send" value="Verstuur">
<input type="reset" name="reset" value="Reset formulier"><br>
</form>
</body>
</html>
-------------------------------------------------------
2:
From: [email protected]
To: #email#
Subject: Uw formulier

U heeft het volgende ingevuld:
Naam: #naam#
Email: #email#


-----------------------------------------------------

what do I do wrong?
gr Jeroen
:D
 
jeroengielen said:
I tried allready 3 hours...
I know i must use CGI...
But can someone explain me how?
I want just that a visitor can send a mail from my site to me...

There must be 2 documents
1html and an other txt:
There must be a third as well.

Do you have a file in your cgi-bin directory named mail.cgi?

What errors are you getting when you fill in the data on your html form and click on "Verstuur"?

Jeff
 
fault:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/1.3.29 Server at www.jeroengielen.be Port 80

========================================
http://www.jeroengielen.be/form.html

========================================
#!/usr/local/bin/perl --
require ("cgi-lib.pl");
&ReadParse;

#change the following to your uername and your email-address. Make sure you
# don't remove the backslash or it will not work!

$send_to="jeroengielen\@mail.be";


#Author: Hasan Naseer

#What is this Program?
#This is a simple Perl implementation of a post-query function. It uses the
#Perl library and the special function from it called ReadParse. Recall that
#ReadParse creates an associative array %in that contains all the fields
#submitted by the form.

#Bibliography
#The information to write this program can be gotten from:
#http://www.cc.ukans.edu/~acs/docs/other/forms-intro.shtml
#http://www.cc.ukans.edu/~acs/docs/other/cgi-with-perl.shtml
#It also requires the knowledge of Perl programming.
#The following line tells the browser that the content of the text that is
#being sent to it is HTML text as opposed to plain text. This means that
#only HTML commands will be understood by the browser when it recieves
#the file.

print "Content-type:text/html\n\n";

#The following code prints out the header of the HTML file that the viewer
#is going to be looking at. This is output that will be on the screen.

print <<END_OF_MESSAGE;
<html>
<title>Thank You Page</title>
<h1>Query Results</h1>
<p>You submitted the following name/value pairs:
END_OF_MESSAGE
#Here is the main program. The name of each field in the form
#submitted along with it's value is printed out as an unordered list.

print "<ul>";
foreach $key (sort keys %in) {
print "<li>$key = $in{$key}\n";
}
print "</ul>";

#send output to the mail program. This sets up the header for the mail program.
open (MAIL, "| /usr/lib/sendmail -oi -n -t" );
print MAIL<<MESSAGE_TO_USER;
To:$send_to
MESSAGE_TO_USER
foreach $key (sort keys %in) {
print MAIL "$key = $in{$key}\n";
}
#the end of the HTML document.
close MAIL;
print "</html>";
 
Do any cgi scripts work? Miight want to make sure the cgi-bin belongs to username: username and not username:somethingelse
 
is there an other way?

Is there an other way to make a form on the internet..???
Can someone give me an easy way?
greets Jeroen
 
Re: is there an other way?

jeroengielen said:
Is there an other way to make a form on the internet..???
Can someone give me an easy way?
greets Jeroen

You could try it in PHP.
Due to the fact you're Dutch, and my Dutch typing skills are a bit better, I'll continue my message in Dutch.

===
Je zou het dus kunnen proberen met PHP; hierbij wil ik een stuk voorbeeld code geven, maar ik vraag er wel bij of je er geen copyrights van jezelf bij wilt zetten in de stijl van 'Ik heb dit gemaakt' ;)
Code:
	echo "<div align='center'><b>Contact formulier</b></div><br />";

	if (!$send)
	{
		?>
		<form action='/contact.php&send=true' method='post'>
	<table border='0'>
		<tr><td width='60%'><font class='tekst'>Voornaam </font><font color='red'>*</font></td><td><input type='text' name='voornaam' class='InputForm' maxlength='75' /></td></tr>
		<tr><td width='60%'><font class='tekst'>Achternaam </font><font color='red'>*</font></td><td><input type='text' name='achternaam' class='InputForm' maxlength='75' /></td></tr>
		<tr><td width='60%'><font class='tekst'>E-mail adres </font><font color='red'>*</font></td><td><input type='text' name='email' class='InputForm' maxlength='75' /></td></tr>
		<tr><td width='60%'><font class='tekst'>Telefoonnummer </font></td><td><input type='text' name='telefoon' value='' class='InputForm' maxlength='75' /></td></tr>
		<tr><td width='60%'><font class='tekst'>Opmerkingen of vragen </font><font color='red'>*</font></td><td><textarea rows='5' cols='20' name='opmerkingen'></textarea></td></tr>
	</table>
	<input type='hidden' name='send' value='True' />
	<br /><font color='red'>*</font> <font class='tekst'>Dit veld is verplicht</font><br />
	<div align='center'><input type='submit' value='Verstuur' name='submit' /> <input type='reset' value='Wis ingevulde informatie' /></div></form>
	<?PHP
	}
	else
	{
		//Dit is het stuk waarin het form afgehandeld dient te worden...
		$die=false; //Zorg ervoor dat de uitvoering door blijft gaan op het moment dat alles ingevoerd is
		if ($_POST["email"]=="" || $_POST["voornaam"]=="" || $_POST["achternaam"]=="" || $_POST["opmerkingen"]=="")
		{
			//Niet alle velden zijn ingevoerd...
			echo "<div class='tekst'><font color='red'>Waarschuwing: Niet alle verplichte velden zijn ingevoerd. U kunt terug gaan door op <a href='javascript:history.go(-1)'>deze knop</a></font></div>";
			$die=true;
		}
	
		if($die==false)
		{
			//Bouw het te versturen mailtje op en begin met verzenden
			$message="
Beste blah,

Er is een nieuw bericht ingezonden via het contact formulier.
Gegevens:
=========
Voornaam: ".$_POST["voornaam"]."
Achternaam: ".$_POST["achternaam"]."
E-mail adres: ".$_POST["email"]."
Telefoonnummer: ".$_POST["telefoon"]."

Opmerking of vraag:
=
".$_POST["opmerkingen"]."
=

Met vriendelijke groet,
De webserver";
			$subject="Ingevuld contactformulier van site";
			$headers="From: ".$_POST["voornaam"]." ".$_POST["achternaam"]." <".$_POST["email"].">\r\n";
			$headers.="X-Mailer: PHP/" . phpversion();
			$verstuuraan="[email protected]";
			mail($verstuuraan,$subject,$message,$headers);
			// Geef bedank bericht weer.
			
			//Toch maar even kappen met PHP code, anders is het voor sommigen een beetje onleesbaar...
			?>
			<div class='tekst'>Bedankt voor het inzenden van uw vraag. Ik zal zo snel mogelijk proberen een antwoord te sturen.</div>
			<?PHP
		}

Dit zou op iedere PHP enabled webserver moeten werken. Ik host het hier op een stel domeinen op de DA servers van mijn bedrijf, dus onder DA werkt het, zolang de e-mail instellingen goed staan.

back to English;
With the piece of sample code, anyone who would think a bit, could impliment it :)
If you do, I only ask you not to take credit for it, so please don't include copyrights or messages stating you made it ;)
 
jeroengielen said:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
You can ignore the above part of the error; as we all should know by now, DA returns this for all errors unless custom error pages have been implemented.
This URL fails this morning; I imagine you're moving forward and I hope you're getting somewhere.
#!/usr/local/bin/perl --
require ("cgi-lib.pl");
&ReadParse;
I've not bothered to copy the rest of this program.

What is this program called? According to your html in a prior post to this thread, this should be called mail.cgi. Is it?

Have you tried changing it's name to mail.pl (and also changing the call in the html file to mail.pl)?

what does the "ls -al" directory output for the file show?

Jeff
 
ok thanks i menage...
I use now a php script a bit less difficult
thank you for all help
gr Jeroen
 
Back
Top