...

View Full Version : More than 2 forms in 1???



sabian1982
02-09-2006, 02:05 PM
What im looking to do is create a varied mail form on one page using php. What i mean by this is that i want to put a radio button list or drop down menu which has a number of different options (for example: 'general' (default), 'complaint' and 'add link'

The General form (which is displayed by default) has 3 input boxes (name, email, comment). When the drop down menu or radio button is changed to (for example) 'add link' the form changes to display 4 input boxes with different names/inputs (name, email, url, comments).

I'm really no good at php so could someone suggest help me sort this out? its simply so i dont have to have seperate pages for each individual form and dont have to put 2 or 3 different forms on the one page (hence making the page length rather long). Im very limited when it comes to programming however i can gather that the scripting would some how use an if statement to see what dropdown option has been selected... other than that i haven't a clue.

For finished working forum would then go on http://www.dietdebate.co.uk/contactus.php

degsy
02-09-2006, 04:07 PM
There are a few different options.

You could dynamically add form elements using javascript, but I wouldn't go down that route.

I would create seperate forms, but only show the form wanted. You can do this in PHP by submitting the page and checking the variable.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST['Submit'])){
foreach($_POST as $key => $val){
echo "$key: $val <br>";
}
}
?>
<form name="form1" method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">
<table width="600" border="1" cellspacing="0" cellpadding="2">
<tr>
<td scope="col">Name</td>
<td scope="col"><input name="name" type="text" id="name" value="<?=$_REQUEST['name']?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text" id="email" value="<?=$_REQUEST['email']?>"></td>
</tr>
<tr>
<td>Complaint subject </td>
<td><p>
<label>
<input type="radio" name="complaint" value="general" <?php if($_REQUEST['complaint'] == 'general'){ echo 'checked'; } ?> onclick="this.form.submit()">
General</label>
<br>
<label>
<input type="radio" name="complaint" value="url" <?php if($_REQUEST['complaint'] == 'url'){ echo 'checked'; } ?> onclick="this.form.submit()">
Report URL</label>
<br>
</p></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comments" id="comments"><?=$_REQUEST['comments']?></textarea></td>
</tr>
<?php
if(isset($_REQUEST['complaint']) && $_REQUEST['complaint'] == 'url'){
?>
<tr>
<td>Report URL </td>
<td><input name="url" type="text" id="url" value="<?=$_REQUEST['url']?>"></td>
</tr>
<?php
}
?>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>




Another way would be to setup seperate forms and use Ajax to include them.
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum