【问题标题】:Submitting form from different <div> HTML从不同的 <div> HTML 提交表单
【发布时间】:2012-08-06 10:33:41
【问题描述】:

我在使用 2 个不同的 div(标签)提交表单时遇到问题。我想提交此表单中的所有值.. 但是当我提交时,我仅从 (div class="tab1") 而不是从 div class="tab2" 收到的值。即使使用不同的 div,我如何提交所有值

page.php

<div class="tab1">
<h2>Basic Information</h2>
<form name="pages_details" method="post" action="pages/save_pages.php">
<table>  
    <tr>  
        <td>Name:</td>  
        <td><input name="name" type="text" ></input></td>  
    </tr>  
    <tr>  
        <td>Order:</td>  
        <td><input name="ord" type="text"></input></td>  
    </tr> 
</table>
</div>
<div class="tab2">
<h2>Additional Information</h2>
<table>  
 <tr>  
    <td>Special:</td>  
    <td><input name="special" type="text" ></input></td>  
 </tr> 
 <tr>  
    <td>Title:</td>  
    <td><input name="title" type="text"></input></td>  
 </tr> 
</table>
</div>
<input type="submit" name="save" value="save">
</form>

save_pages.php

<?php
$name = $_REQUEST['name'];
$ord = $_REQUEST['ord'];
$special = $_REQUEST['special'];
$title = $_REQUEST['title'];

echo $name;
echo $ord;
echo $special;
echo $title;
?>

【问题讨论】:

  • 如果将第一个 div 放在表单标签中会发生什么?你真的不应该像那样重叠它们。
  • 使用form 而不是(可能是显示)div 来提交您的值?
  • @Alex :你的意思是把 div 标签放在表单标签里面吗?我已经尝试过了,但它使标签不起作用。
  • @Jared:你能给我举个例子吗?
  • @hemiz 是的,我就是这个意思。

标签: php html


【解决方案1】:

尽量确保以正确的顺序关闭标签。 像这样构建代码可能会导致一些奇怪的错误。

不对:

<div>
<form>    
</div>
</form>

所以你可能想这样做。

<form>
<div>
</div>
</form>

【讨论】:

  • 我编辑了你的答案,因为我几乎误解了你的答案。
  • @jared
    。我做到了,但仍然无法正常工作
  • @hemiz - 这是一个有效的,主要是题外话的示例标记。
【解决方案2】:

我建议根据您的情况使用 jquery ajax 提交表单。

例如:

var datas = $(form).serialize();
$.post("pages/save_pages.php", datas, function(){

});

参考: 发布 - http://api.jquery.com/jQuery.post/ 序列化 - http://api.jquery.com/serialize/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2013-08-20
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多