SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Dublin
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question If only it was possible to have nested forms!

    Hi,

    If only it was possible to have nested forms!

    I have a script with a form that takes details from a user posting an ad for house renting.

    The script takes in details such as:

    Property Type:
    Property Address:
    House description:

    This is done easily with a form but here's the tricky bit. Within that form I want the the user to select from a drop down menu how many bedrooms available in their house, if they select for example 2 bedrooms then the script will dynamically create fields for Bedroom 1 and Bedroom 2 for the user to fill in.

    I can do this on a seperate script, here's the code below:

    <form method="POST" name="roomcount" action="<?=$_SERVER['PHP_SELF']?>">
    <p><select size="1" name="Dropdown1" onchange=roomcount.submit()>
    <option value=" ">[Select]</option>
    <option value="1">Option1</option>
    <option value="2">Option2</option>
    <option value="3">Option3</option>
    </select>
    <form>
    </td>
    </tr>

    <?php
    $count = intval($_POST['Dropdown1']);
    while(++$i <= $count)
    {
    echo "<b><u>Bedroom $i</u></b> <br>";
    echo "Bedroom Type: <select name=bedroom_type>";
    echo "<option value=single>Single Room";
    echo "<option value=double>Double Room";
    echo "<select> <br>";

    echo "Ensuite: <input type=radio name=ensuite value=Yes> Yes ";
    echo "<input type=radio name=ensuite value=No> No <br>";
    echo "Rent: <input type=text name=rent Size=25><br><br>";
    }
    ?>

    The problem is I can't put this form within the other form as it's not possible in HTML, can anyone see a solution to this?

  2. #2
    Romans 12:2 codyrockx's Avatar
    Join Date
    Jul 2003
    Location
    Newberg, Oregon
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you not simply place the php code within the html parameters? And you also forgot the closing option tags in the php echo.

    HTML Code:
      <form method="POST" name="roomcount" action="<?=$_SERVER['PHP_SELF']?>">
      <p><select size="1" name="Dropdown1" onchange=roomcount.submit()>
      <option value=" ">[Select]</option>
      <option value="1">Option1</option>
      <option value="2">Option2</option>
      <option value="3">Option3</option>
      </select>
     
      <?php
       $count = intval($_POST['Dropdown1']);
       while(++$i <= $count)
       {
       echo "<b><u>Bedroom $i</u></b> <br>";
       echo "Bedroom Type: <select name=bedroom_type>";
       echo "<option value=single>Single Room</option>";
       echo "<option value=double>Double Room</option>";
       echo "</select> <br>";
       
       echo "Ensuite: <input type=radio name=ensuite value=Yes> Yes ";
       echo "<input type=radio name=ensuite value=No> No <br>";
       echo "Rent: <input type=text name=rent Size=25><br><br>";
       }
       ?>
      <form>
       	</td>
      	</tr>
    Codyrobert.com - Designer and Developer


Bookmarks

Posting Permissions

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