Hi,

I'm a bit new to php and am hoping that someone would be kind enough to help me with my problem. What I want to achieve is as follows: I created a form in my .php file, once I click the add button I want another form to appear on the same page but overwrite/delete the previous form. Here is what I need help with:

How can I output another form (on the same .php page) and overwrite/delete the previous form using php "without having to create another .php file"?

Here is my forms.php code:

<html>

<head>

<link rel="stylesheet" type="text/css" href="forms.css" />
<title>about forms</title>

</head>

<body>

<form action="" method="post" id="form1">
   <div id="container">
      <div id="header">About Forms</div>
      <div id="name">Name</div>
      <div id="nametext">
         &nbsp;&nbsp;<input type="text" name="nameEntry" size="30"></div>
      <div id="item"><br>Item Type</div>
      <div id="itemchoice">
         &nbsp;&nbsp;<input type="radio" name="itemtype" value="Book" checked>
            <b>Book</b><br>
         &nbsp;&nbsp;<input type="radio" name="itemtype" value="Author">
            <b>Author</b><br>
         &nbsp;&nbsp;<input type="radio" name="itemtype" value="Publisher">
            <b>Publisher</b>
      </div>
      <div id="book"><b>Book Type</b> <font size="1px">(if applicable)</font></div>
      <div id="bookchoice"><select name="booktype">
                              <option value="Horror" selected><b>Horror</b>
                              <option value="Suspense"><b>Suspense</b>
                              <option value="Romance"><b>Romance</b>
                           </select>		
      </div>
      <div id="displaydebug">Display Debug</div>
      <div id="checkdebug">
         &nbsp;&nbsp;<input type="checkbox" name="debug">
         <font size="1px">Check if you want to display</font></div>
      <div id="buttons"><input type="submit" name="search" value="Search">
                        <input type="submit" name="add" value="Add">
      </div>
   </div>
   <div id="footer">Designed and Developed by me, Copyright 2011</div>		
</form>

<?php
   if (isset($_POST["add"])) {
      echo '<pre>';
      echo (print_r($_POST));
      echo '</pre>';		
   }	
   if (isset($_POST["search"])) {
      echo "Search button has not yet been implemented.";
   }
?>

</body>

</html>

Any help and suggestions would be appreciated. Thanks! =)

Member Avatar for diafol

You can use include files for the forms (pure php).
OR you can place both forms on the page and then toggle their visibility with js/css.

If you're creating a form wizard, there are loads of great jquery implementations. 'stepy' is one that I've used - looks good too. http://www.wbotelhos.com/stepy/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.