简体   繁体   English

用输入的内容替换文本输入值

[英]Replace text input value with whatever is typed inside

I've made an update form for my projects on my site. 我已经为自己网站上的项目制作了更新表格。 In my php, I populate the values of the input text tags with the existing information from the database. 在我的php中,我用数据库中的现有信息填充输入文本标签的值。 I want to be able to change the value of the input tags to whatever I type, but doesn't seem to be working. 我希望能够将输入标签的值更改为我键入的任何内容,但似乎无法正常工作。 When I hit submit, the values don't change at all (I checked my database, the fields' values are the same as before). 当我点击提交时,这些值完全没有改变(我检查了数据库,这些字段的值与以前相同)。

I feel like this is a really straightforward idea, basically any WYSIWYG/CMS functions the same. 我觉得这是一个非常简单的主意,基本上所有WYSIWYG / CMS功能都相同。 What am I doing wrong? 我究竟做错了什么? What Javascript/jQuery might I need to accomplish this? 我可能需要什么Javascript / jQuery来完成此任务?

(Oops) Here's My Code (糟糕)这是我的代码

(I'm using CodeIgniter) Here's my PHP for the input tag: (我正在使用CodeIgniter)这是输入代码的PHP:

<?php 
    $title_input = array(
        'name' => 'title',
        'id' => 'title',
        'autocomplete' => 'off'
    );

    if (isset($updating)) {
        $title_input['value'] = $project->title;
    }
    echo form_input($title_input);
?>

Which spits out: 哪个吐出来:

<input type="text" name="title" value="My Project Title" id="title" autocomplete="off">

When the form is submitted, this is how I (try to) change the info in the database: 提交表单后,这就是我(尝试)更改数据库中信息的方式:

$project->title = $this->input->post('title');

It's the exact same code I use for when I create a NEW project, except I was hoping that it would detect the changed input text value. 与创建新项目时使用的代码完全相同,只是我希望它可以检测到更改的输入文本值。 :/ :/

I have a page currently that takes input and stores it in the database and when the page is revisited, if there is any information previously stored, it is loaded and can be edited. 我当前有一个页面,该页面接受输入并将其存储在数据库中,并且当重新访问该页面时,如果以前存储了任何信息,则将其加载并可以进行编辑。 upon submit, I save again. 提交后,我再次保存。

Things you should consider: 您应该考虑的事项:

  • Ensure you are checking $_POST in the function handling the update. 确保在处理更新的函数中检查$ _POST。 If you are using too separate functions(for new and for update) then use echo statement to check that all if statements parameters are valid and not empty). 如果您使用的功能过于分离(用于新功能和更新功能),请使用echo语句检查所有语句参数是否有效且不为空。
  • Use isset as much as you can with combination of != '' and this will make sure if statement is correctly evaluated. 尽可能结合使用isset与!=''结合使用,这将确保语句是否被正确评估。
  • Maintain a separate model function to handle update. 维护一个单独的模型功能来处理更新。 Best thing to do imho is to save the whole form again. 恕我直言,最好的办法是再次保存整个表单。 Do not only check for modified fields. 不仅检查已修改的字段。 You can check for required fields not to be set empty but other than that, resubmit the whole form if possible 您可以检查是否将必填字段设置为空,否则,请重新提交整个表单(如果可能)

More assistance could be provided if you willing to share your code 如果您愿意共享代码,则可以提供更多帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将输入文本字段更改为标签 javascript 中输入类型值的标签 - change input text field into label with input typed value inside label javascript 如何使输入中键入的文本显示在单独的div中 - How to make the text that are typed inside the input to appear into a seperate div 替换内部值 <input></input> 用jQuery - Replace value inside <input> </input> with jquery 用文本框替换表单元格,读取键入的值,然后使用jquery用新值替换表单元格 - replace a table cell with the text box, read the value typed and replace back the table cell with the new value using jquery 如何将按钮的数据属性设置为输入[type = text]中设置的任何值? - How to set the data-attribute of a button to whatever value set in an input [type=text]? 将输入字段的值设置为单击的任何值 - Set value of input field to whatever is clicked 从内部隐藏输入中选择替换值 - Replace value from select inside hidden input 如果不为空,如何在加载时用文本替换输入,如果最初为空并键入,如何在模糊时替换为输入? - How to replace input with text on load if not empty, but also on blur if initially empty and typed into? IE8:模式弹出窗口中的文本输入不显示键入的文本 - IE8: text input inside a modal popup doesn't show typed text 如何在擦除输入中键入的值后在跨度上显示默认文本值 - how to display default text value on span after erasing the value typed on input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM