Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    More than 2 forms in 1???

    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

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    <!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/dynamici...jaxcontent.htm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •