【问题标题】:<input> element does not post data?<input> 元素不发布数据?
【发布时间】:2015-04-20 14:20:03
【问题描述】:

我有一个表单页面,当我提交此表单时,所有输入都已成功发布,除了这个:

<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" 
  <?php if($this->data['kullanici_id']){echo 'readonly';} ?>  
  value="<?php echo $this->data['kullanici_id']?>">

但是为什么呢?

-这是我的 .phtml 文件:

<html>
<head>

</head>
<body>
<form  enctype="multipart/form-data" action="/admin/kaydet" method="post" onSubmit="javascript: beforeSubmit();">
    <?php if(strlen($this->data['id'])):?>
        <input type="hidden" name="id" value="<?php echo $this->data['id']?>">
    <?php endif;?>
    <font color="green"><h3>DÜZENLE</h3></font>
    <img src="/foto/<?php echo $this->data['fotograf']?>" height="110" width="110" align="left" />
    <table class="table">
        <tr>
            <td>T.C. Kimlik No.:</td>
            <td><input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?>  value="<?php echo $this->data['kullanici_id']?>"></td>
        </tr>
        <?php if(!strlen($this->data['id'])):?>
        <tr>
            <td>Parola:</td>
            <td><input id="password2" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
        </tr>
            <tr>
                <td>Parola Tekrar:</td>
                <td><input onchange="passwordCheck(this.value)" class="form-control" type="password" name="parola" value="<?php echo $this->data['parola']?>"></td>
        </tr>
        <?php endif; ?>
    </table>
    <td><button type="submit" class="btn btn-success btn-sm glyphicon glyphicon-floppy-disk">KAYDET</button> </td>
</form>
</body>
</html>

如果我有身份证;页面看起来像一个编辑成员页面,如果我没有的话;页面将添加一个新成员。在 id="TC" 输入中,如果我编辑一个成员,这个输入不应该改变,所以我添加了一个 readonly 来解决这个问题。但是当我提交时,输入不会发布。 对不起我的英语不好:D

【问题讨论】:

  • 似乎该字段被设置为readonly,因此任何更改都将被丢弃并发布到服务器。您可能想向我们展示实际帖子的样子。
  • 请发布完整的源代码。
  • @IsaacKleinman 因为在给定的代码中有readonly 而不是disabled。所以肯定会处理的
  • 您的输入是包含值还是为空?我的意思是,当您查看表单时,如果您看到一些价值 :-) 而且您是否正在尝试 var_dump() 整个帖子?
  • 是你&lt;form&gt;里面的输入吗?

标签: php html forms input


【解决方案1】:

您的字段未提交的原因是它设置为readonly

原因是“如果用户无法更改字段,则没有必要提交它,因为值将始终保持不变”。

减轻这种行为的一种方法是添加具有相同名称的隐藏字段

<input type="hidden" name="kullanici_id" value="<?php echo $this->data['kullanici_id']?>"> />
<input id="TC" class="form-control" name="kullanici_id" type="text" onchange="edit()" <?php if($this->data['kullanici_id']){echo 'readonly';} ?>   value="<?php echo $this->data['kullanici_id']?>" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多