dongyun8075 2016-06-19 13:12 采纳率: 100%
浏览 22
已采纳

输入值是否可以与HTML表单中的占位符相同?

I have an HTML form that accepts a CVV number as one of the field items -

<label for="cvv">CVV</label>
<input type="text" placeholder="123" maxlength="3" id="cvv" name="cvv">

As you can see, it has a placeholder="123". I'm entering the CVV number into my database as part of an array -

$pay = array(
    'cardno' => $cardno,
    'exp' => $this->input->post('exp'),
    'cvv' => $this->input->post('cvv'),
    'name' => $this->input->post('name'),
    'org' => $this->session->userdata['user_data']['org']
    );
$this->db->insert('payment', $pay);

I'm able to enter any CVV value into the database except 123 which is the same as the placeholder value. I keep getting the following error -

Error Number: 1366

Incorrect integer value: '' for column 'cvv' at row 1

INSERT INTO `payment` (`cardno`, `exp`, `cvv`, `name`, `org`) VALUES ('6547893210258135', '04/20', '', 'Joe Bloggs', '15')

Filename: C:\xampp\htdocs\ci_redesign_newdb\system\database\DB_driver.php

Line Number: 330

When I print the $pay array before inserting it into the database, with cvv as 123, the CVV field is empty -

Array ( [cardno] => 6547893210258135 [exp] => 04/20 [cvv] => [name] => Joe Bloggs [org] => 15 )

However, if I change the CVV value to anything else, the CVV field gets populated -

Array ( [cardno] => 6547893210258135 [exp] => 04/20 [cvv] => 103 [name] => Joe Bloggs [org] => 15 )

And since that field gets populated, I'm able to enter it into the database without any errors. What could be the reason the form isn't accepting a value that is the same as the field's placeholder, i.e., 123 in this case?

EDIT 1

This problem seems to be present for all input fields in the form. I only noticed it for cvv since I happened to enter 123 as a test. So, it looks like all the fields where the entered input value is the same as the placeholder value are not being input.

EDIT 2 - PROBLEM SOURCE

It looks like the problem is originating from the jQuery source file version 2.0.3. I commented out the file in my code -

<script src='<?php echo base_url(); ?>assets/js/jquery-2.0.3.min.js'></script>

and I was able to post the input values which were the same as my placeholder -

Array ( [cardno] => 1234567890123456 [exp] => mm/yy [cvv] => 123 [name] => Name [org] => 15 )

Is this something that can be solved by editing the jQuery source file? Should I be making such changes? Don't want to make changes that could cause problems elsewhere.

  • 写回答

1条回答 默认 最新

  • dongze8698 2016-06-20 01:01
    关注

    This is really weird. I'm sure there is some JavaScript code or a library you are using is causing this.

    A possible way around your problem is to remove/change the placeholder attribution of your inputs right before submiting it.

    For example;

    <form id="yourform" name="yourform">
     <input type="text" placeholder="123" id="cvv"/>
     <div class="button" onclick="submitForm()">Submit</div>
    </form>
    

    In JS;

    function submitForm(){
       document.getElementById("cvv").placeholder = "";
        //Do it for all of your input elems.
    
       document.yourform.submit();
    }
    

    Not sure it is going to work, and I know not the actual proper way to solve it, but would do the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教