2013-08-07 78 views
0

我想在窗體中使用窗體。 我有以下代碼。窗體與在窗體中的PHP

<?php session_start(); 
if(!isset($_SESSION['logged_in'])){ 
    echo "Sorry! You need to log in to add Information. <a href='login.php'>Login</a>"; 
} else { 
?> 

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>iWant | in case you want anything</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <!--link rel="stylesheet/less" href="less/bootstrap.less" type="text/css" /--> 
    <!--link rel="stylesheet/less" href="less/responsive.less" type="text/css" /--> 
    <!--script src="js/less-1.3.3.min.js"></script--> 
    <!--append ‘#!watch’ to the browser URL, then refresh the page. --> 

    <link href="css/bootstrap.min.css" rel="stylesheet"> 
    <link href="css/bootstrap-responsive.min.css" rel="stylesheet"> 
    <link href="css/bootstrap-fileupload.min.css" rel="stylesheet"> 
    <link href="css/bootstrap-fileupload.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="jquery.min.js"></script> 

    <script src="upload.js"></script> 

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> 
    <!--[if lt IE 9]> 
    <script src="js/html5shiv.js"></script> 
    <![endif]--> 

    <!-- Fav and touch icons --> 
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/apple-touch-icon-114-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72-precomposed.png"> 
    <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-57-precomposed.png"> 
    <link rel="shortcut icon" href="img/favicon.png"> 

    <script type="text/javascript" src="js/jquery.min.js"></script> 
    <script type="text/javascript" src="js/bootstrap.min.js"></script> 
    <script type="text/javascript" src="js/scripts.js"></script> 
    <script type="text/javascript" src="js/bootstrap-fileupload.js"></script> 
    <script type="text/javascript" src="js/bootstrap-fileupload.min.js"></script> 
    <script type="text/javascript" src="js/jquery.min.js"></script> 
</head> 

<body> 
<div class="container-fluid"> 
    <div class="row-fluid"> 
     <div class="span4"> 
      <h3> 
       iWant | In Case U Want Anything 
      </h3> 
     </div> 
     <div class="span4"> 
      <form class="form-search"> 
       <input type="text" class="input-medium search-query"> <button type="submit" class="btn">Search</button> 
      </form> 
     </div> 
     <div class="span4"> 
      <a href="login.php" class="btn" type="button">Login</a> <a href="signup.php" class="btn" type="button">Sign Up</a> 
     </div> 
    </div> 
    <div class="row-fluid"> 
     <div class="span12"> 
      <div class="navbar navbar-inverse"> 
       <div class="navbar-inner"> 
        <div class="container-fluid"> 
         <a data-target=".navbar-responsive-collapse" data-toggle="collapse" class="btn btn-navbar"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></a> <a href="index.php" class="brand">iWant</a> 
         <div class="nav-collapse collapse navbar-responsive-collapse"> 
          <ul class="nav"> 
           <li> 
            <a href="#">Home</a> 
           </li> 
           <li> 
            <a href="#">About iWant</a> 
           </li> 
           <li> 
            <a href="#">Contact iWant</a> 
           </li> 
          </ul> 
          <ul class="nav pull-right"> 
           <li> 
            <a href="#">My iWant</a> 
           </li> 
           <li class="divider-vertical"> 
           </li> 
           <li class="dropdown"> 
            <a data-toggle="dropdown" class="dropdown-toggle" href="#">Post Adds<strong class="caret"></strong></a> 
            <ul class="dropdown-menu"> 
             <li> 
              <a href="room.php">Room</a> 
             </li> 
             <li> 
              <a href="#">Hostel</a> 
             </li> 
             <li> 
              <a href="#">Apartment</a> 
             </li> 
             <li> 
              <a href="#">Land</a> 
             </li> 
             <li> 
              <a href="#">House</a> 
             </li> 
             <li> 
              <a href="#">Vehicles</a> 
             </li> 
             <li> 
              <a href="#">Hotels</a> 
             </li> 
             <li> 
              <a href="#">Mobile Phones</a> 
             </li> 
            </ul> 
           </li> 
          </ul> 
         </div> 

        </div> 
       </div> 

      </div> 

      <div class="well"> 

      <form id="Room Details" class="form-horizontal" method="get" action="roomKoDesc.php"> 
      <?php echo "<input type='hidden' name='clientId' value='".$_SESSION['clientId']."'>"; ?> 
      <legend>Post Rooms</legend> 
      <div class="control-group"> 
      <label class="control-label">Contact Number</label> 
      <div class="controls"> 
       <div class="input-prepend"> 
        <input type="text" class="input-xlarge" id="contact" name="contact" placeholder="Your Contact"> 
       </div> 
      </div> 
     </div> 
     <div class="control-group"> 
      <label class="control-label">Location of Rooms</label> 
      <div class="controls"> 
       <div class="input-prepend"> 
        <input type="text" class="input-xlarge" id="location" name="location" placeholder="rooms location"> 
       </div> 
      </div> 
     </div> 
     <div class="control-group "> 
      <label class="control-label">Number of Rooms</label> 
      <div class="controls"> 
       <div class="input-prepend"> 
        <input type="text" class="input-xlarge" id="number" name="number" placeholder="no. of rooms"> 
       </div> 
      </div> 
     </div> 
     <div class="control-group"> 
      <label class="control-label">Price per Room</label> 
      <div class="controls"> 
       <div class="input-prepend"> 
        <input type="text" class="input-xlarge" id="price" name="price" placeholder="price per room"> 
       </div> 
      </div> 
     </div> 
     <div class="control-group"> 
      <label class="control-label">Sqare meter</label> 
      <div class="controls">   
        <div class="input-prepend"> 
        <input type="text" class="input-xlarge" id="size" name="size" placeholder="Area of rooms"> 
       </div> 

      </div> 
     </div> 







    <div id ="main"> 

     <form method="post" enctype="multipart/form-data" action="upload.php"> 
      <input type="file" name="images" id="images" multiple /> 
      <button type="submit" id="btn">Upload Files!</button> 
     </form> 

    <div id="response"></div> 
     <ul id="image-list"> 

     </ul> 
    </div> 



     <div class="control-group"> 
      <label class="control-label">Description</label> 
      <div class="controls"> 
       <div class="input-prepend"> 
        <textarea rows="4" cols="50" input type="text" class="input-xlarge" id="description" name="description" placeholder="Description"></textarea> 

       </div> 
      </div> 
     </div> 
      <input type="submit" class="btn btn-success" value="Submit" /> 
     </form> 

      </div> 

    </div> 
</div> 
</body> 
</html> 
<?php } ?> 

我的輸出看起來像這樣Example

但提交按鈕亙古不直接到另一個網頁。 和上傳作品
我怎樣才能使兩個提交按鈕的工作? 是否有任何簡單的procress使用嵌套形式。

+1

請仔細閱讀本'HTTP:// stackoverflow.com /問題/ 3430214 /表單內-A型 - 是 - 是 - alright' –

+0

形式,形式是無效的代碼和不可能。如果你需要在窗體中嵌套表單,你在概念階段做了錯誤的事情。 – mondjunge

+1

@DrixsonOseña我認爲你的意思是=> [**請閱讀此**](http://stackoverflow.com/questions/3430214/form-inside-a-form-is-that-alright);-) –

回答

1
<input type="file" name="images" id="images" multiple /> 

對整個表單使用這一點,不要使用2個單獨的表單。當表單提交時,您可以上傳文件。

+0

我也需要重定向到下一頁..只是看我的代碼 – enjal

+0

'header(「Location:myfile.php」)'這是重定向的一種方式,但是,您可以在整個表單上創建一個包裝,當用戶提交表單時,內容將被隱藏並顯示您想要顯示的內容。 –

0

Enjal,

你爲什麼要使用多個形式一頁。你可以通過使用單一的表單來做同樣的事情。只需使用Javascript來改變表單'action'屬性。該代碼會是這樣,

<html> 
<head> 
<script type="text/javascript" language="javascript"> 
function changeaction(url) 
{ 
document.frm.action=url; 
document.frm.submit(); 

} 
</script> 
</head> 
<body> 
<form name="frm" action="" method="post"> 
<input type="submit" name="submit" value="submit1" onclick="return changeaction('upload.php');"> 
<input type="submit" name="submit" value="submit2" onclick="return changeaction('index.php');"> 

</form> 
</body> 
</html>