形式与PHP中的形式

时间:2013-08-07 07:53:21

标签: php mysql

我想在表单中使用表单。 我有以下代码。

<?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使用嵌套表单。

2 个答案:

答案 0 :(得分:1)

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

仅将此用于整个表单,不要使用2个单独的表单。提交表单时,您也可以上传文件。

答案 1 :(得分: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>