PDA

View Full Version : designing forms, please help, thanks



mr friendly
18 Jul 2007, 02:07 PM
im a new web designer based in orange county california. im trying to teach myself web design using online tutorials and books.

im currently building a page using dreamweaver and i have 2 forms on the page. in the first form i want ppl to submit their name, email and then write comments and the SUBMIT button should send all their info to my email.

*how can i get the form to reset after they submit the form, but make the browser stay on the same page. i want to notoify them that their message has been sent without loading a new page

on the second form i want them to enter in their name, their friends email addresses and then i already have a comment written for them, its a link to my site. when they hit the SUBMIT button, i want the form to be sent, via email to the addresses that they type into the designated field.

*how do i do that? do i simply add a hidden field and the in the code instead of 'mailto:example@aol.com' do i somehow point it to send the message to the values in the given box? i.e. 'mailto:'see value of FRIENDS_EMAILS textfield'?

any help would be appreciated. ive read several online tutorials but they only cover the basics

someone told me that PHP is the way to go? but im open to any suggestions that could help me.

Littlened
31 Jul 2007, 07:14 AM
I would recommend PHP.

Basically, what you'd do is create your 2 forms and put a hidden field in each form called 'action'. give action a different value for each field, i.e. 'form1' and 'form2'

You would then set both forms to submit to itself i.e. <form method="post" action="forms.php">

At the very top of the forms.php page, you would have some php code which would get all the values from the submitted form and look to see whether the action field contains form1 or form2, from that it can determine which form was submitted.

Then you can use PHP IF statements to tell php to generate email and do what you want each form to do.

Once the form is submitted it'll clear the field values automatically.

Theres a fair bit of learning form you, but heres some code which might help you get started...



<?php

$name = $_REQUEST['name'];
$action = $_REQUEST['action'];

if ($action == 'form1') {
echo "Hello ".$name.", you submitted form 1.";
// put whatever you want to happen when form1 is submitted in here
}

if ($action == 'form2') {
echo "Hello ".$name.", you submitted form 2.";
// put whatever you want to happen when form2 is submitted in here
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form method="post" action="form.php">
Your name:
<input type="text" name="name" />
<input name="action" type="hidden" value="form1" />
<input type="submit" name="Submit" value="Submit" />
</form>

<form method="post" action="form.php">
Your name:
<input type="text" name="name" />
<input name="action" type="hidden" value="form2" />
<input type="submit" name="Submit" value="Submit" />
</form>

</body>
</html>