Computer Science Canada

Forms

Author:  Ravage [ Mon Apr 14, 2003 12:13 pm ]
Post subject:  Forms

I was wondering if there is anyway to make a form without using CGI script (I know this isnt HTML but I dont know where else to put it)

Author:  Blade [ Mon Apr 14, 2003 12:26 pm ]
Post subject: 

you have to use some sort of scripting language... i prefer to use php, so heres an example..
code:

<html>
<form method=post action=accept.php>
Enter your name:<br>
<input type=text name=name><br>
Enter your age:<br>
<input type=text name=age><br>
Select one:<br>
<select name=sel>
<option>Girl
<option>Boy
<option>Man
<option>Woman
<option>I don't know
</select><br>
<input type=submit>
</form>
</html>

that is what a form may look like... and a form handler in php would look like this... although you will have to find a server that has php to be able to execute it.. but anyway, here it is
code:
// name this accept.php so the form can find it
// also put it in the same folder..
<?
echo "Your name is $name<br>";
echo "Your age is $age<br>";
echo "And you are a $sel";
?>

the <? ?> tags are to show that you are starting up the php parser, echo is used to output to the screeen, and if you wanted different things posted you'd use a large if statement, or an array with a while loop. php is much like C++ like its if statements, the semicolon at the end of each line, and so on... although the variables are shows with $'s...

edit:
i would also lke to add that another really good thing about php is you can start it anywhere in an html document, and then end it, and use html for a while... even when you have php running in the document you can unlude tags using echo() like i did in my example of the form handler

Author:  yuethomas [ Mon Apr 14, 2003 4:44 pm ]
Post subject: 

Err, are you sure about the variables' names in PHP part? I remember you have to use $_POST['name'], $_POST['age'], etc. The method=get equivalents are $_GET['name'], $_GET['age'], etc.

Author:  Blade [ Mon Apr 14, 2003 4:51 pm ]
Post subject: 

yeah i'm positive... try it out man... i got it up on one of my old sites...
http://members.lycos.co.uk/devilomayhem/stuffs/form.html

edit: sometimes the servers go down... so try it later if you want to

Author:  yuethomas [ Mon Apr 14, 2003 5:00 pm ]
Post subject: 

It isn't much use unless you post the PHP code for us. =p

(Oh and, the script I wrote myself... it doesn't work)

code:
<BODY>
<?PHP
    echo "USING LINE: you entered ".$line."<BR>";
    echo "USING _POST: you entered ".$_POST['line']."<BR>";
?>
<BR><FORM method="post" action="temp.php"><BR>
<INPUT TYPE="text" NAME="line">
<INPUT TYPE="submit">
</FORM></BODY>


It's at http://osiris.dyndns.info/newsite/sections/temp/temp.php.

Author:  Blade [ Mon Apr 14, 2003 5:25 pm ]
Post subject: 

i did post it... thats exactly what i was using up top, i copied and pasted it, ive been doing it that way for a long time man...

Author:  yuethomas [ Mon Apr 14, 2003 5:27 pm ]
Post subject: 

Oy, my bad, didn't realise they were the same thing.

But my script still doesn't work...

Author:  Blade [ Mon Apr 14, 2003 5:35 pm ]
Post subject: 

it works fine on my server
http://members.lycos.co.uk/devilomayhem/stuffs/temp.php
it's probably the way they have their php set up...

Author:  yuethomas [ Mon Apr 14, 2003 5:43 pm ]
Post subject: 

Thanks, I'll check my php.ini then.

Author:  Blade [ Mon Apr 14, 2003 5:44 pm ]
Post subject: 

do you have your comp running as a server?

Author:  yuethomas [ Mon Apr 14, 2003 6:08 pm ]
Post subject: 

Yes.

Author:  Blade [ Mon Apr 14, 2003 6:20 pm ]
Post subject: 

sweet... i'd like to ask you a couple question... do you have msn or aim?

Author:  octopi [ Mon Apr 14, 2003 7:52 pm ]
Post subject: 

Now, since the OP mentioned not using cgi script (which php, perl, c++ etc.. are.(when used over the internet))

code:
<form action="mailto:somedude@thisplace.com" method="POST" enctype="text/plain">


That will send the form contents to your email address, downside is it uses outlook to send the form, and IE pops up a bunch of warning messages about it.

A much better solution would be to use formmail.pl by Matt Wright.

http://www.scriptarchive.com/formmail.html

You will need perl installed to use it(on your server), but if you search on google you can find versions for php etc..

http://www.google.ca/search?q=formmail+php

Author:  Blade [ Mon Apr 14, 2003 8:17 pm ]
Post subject: 

perl is cgi... php isn't anything like perl

Author:  octopi [ Mon Apr 14, 2003 8:35 pm ]
Post subject: 

Your correct, one could also say that perl and c++ are not alike, but both can, and are used as 'cgi scripts'.

Php is more commonly used like mod_perl is, which runs as a module linked into apache (or whatever major webserver you use.)

However you can use php in the exact same way you would call perl (and originally had to).

code:
#!/usr/bin/php


code:
#!/usr/bin/perl


both those assume a unix machine (with perl, and php installed into /usr/bin)
you can then follow with php code, the exact same you would with perl.

Author:  yuethomas [ Mon Apr 14, 2003 10:44 pm ]
Post subject: 

Well considering that I run a Windows 2000, it's not very helpful to me. Razz

(Blade can you please ask the questions here? ^_^ )

Author:  Blade [ Wed Apr 16, 2003 4:20 pm ]
Post subject: 

lol... its more of a discussion but sure.. i went online and got php, i followed all the instructions for installing it to the server, but it still didnt work properly.... running it on xp should be fine, cuz i had foxserv.. but it doesnt index the files like the normal apache does, when you dont have an index file in the folder... it just says it cant find it... but i'd still like to have php on my server...

confused yet?

Author:  yuethomas [ Sat Apr 19, 2003 10:38 pm ]
Post subject: 

Oh... I have no experience with webservers other than Apache. So, sorry, can't help you there. Sad

Author:  Blade [ Tue Apr 22, 2003 9:57 pm ]
Post subject: 

yuethomas wrote:
Oh... I have no experience with webservers other than Apache. So, sorry, can't help you there. Sad


i was talking about installing php on apache...


: