View Full Version : Name Form


xlilmissjuliex
05-28-2006, 02:06 AM
I need the code for a form. The form only needs a 'name' option and a submit button. For example:

Enter your name: Julie
--SUBMIT--

Once someone hits submit, the page would be redirected to another page in which there will be a welcome paragraph. Example:

Welcome [name]Julie!

Just with the forms information, it will grab the text and use it on some page, link, etc.

This is partly HTML, and party something else I think.

Thanks!

{C-S-S}
05-28-2006, 02:30 AM
well, i know how to do this on one page and it will ask for the name in an prompt, but i dont know how to do it in a diferent window to where it redirects you. but the alert thing will work just the same...almost...

here is the javascript that goes in the head (it needs to be in the head if you want it to ask for name before anything loads):


<script language="javascript">
<!--hide from old browsers
//the promt that will ask for name
var name=prompt('Please enter your name','Name here');
// end hiding -->
</script>


and put this were you want the welcome to be


<script language="javascript">
<!--hide from old browsers
//this is how it displays the welcome
document.write('Hello, ' + name + '! How are you?');
// end hiding -->
</script>


you can replace the "Hello" and "How are you? to what you want. You can even put in HTML tags...

hope it helps ya,

Phil

{C-S-S}
05-28-2006, 02:44 AM
Oh, and i just notest and tried to edit the post, but the time that i had to edit it expired so:

I copied and pasted that exact code in my site and it didnt work because it pasted it in one line, so make sure the lines are all listed the exact way it looks...sorry for the double post,


Phil

xlilmissjuliex
05-28-2006, 03:11 AM
Oh, this worksjust fine! THANKS!! :aniflower

iTom
05-28-2006, 10:53 AM
There is a better way, but it won't work on free hosts. Your host needs to support PHP (look it up)

form.html

<form action="proc_hello.php" method="POST">
Name: <input type="text" name="whoru" />
<input type="submit" value="Submit" />
</form>


proc_hello.php:

<?php
if(empty($_POST['whoru'])) {
?>Please go back and correct errors. <?
} else {
echo "Hello, ".$_POST['whoru']."!";
}
?>


Hope this helps.