简体   繁体   English

将值放入隐藏字段

[英]putting a value in a hidden field

i want to put the value of id field of $info in my form's hidden field 'info_id'.我想将 $info 的 id 字段的值放在表单的隐藏字段“info_id”中。 But every time i put the values in the form field, the info_id remains 0. If i echo $info[0]->id before opening the form it shows the id value but inside the form it doesn't work.What could be the possible problem?但是每次我将值放入表单字段时,info_id 保持为 0。如果我在打开表单之前回显 $info[0]->id 它会显示 id 值但在表单内部它不起作用。可能是什么可能的问题? please help.请帮忙。

The view:风景:

<?php echo $info[0]->Area;?>:</br>
<?php echo $info[0]->Address;?> 

<?php echo form_open('dis_controller', $attributes); ?>
<p>
    <label for="name">name</label>
    <?php echo form_error('name'); ?>
    <br /><input id="name" type="text" name="name"  value="<?php echo set_value('name'); ?>"  />
</p>
<p>
    <label for="discussion">Post a comment</label>
    <?php echo form_error('discussion'); ?>
    <br />
    <?php echo form_textarea( array( 'name' => 'discussion', 'rows' => '5',  'cols'  =>  '80', 'value' => set_value('discussion') ) )?>
</p>

<input id="info_id" type="hidden" name="info_id" value="<?php echo $info[0]->id;?>">

<p>
    <?php echo form_submit( 'submit', 'Submit'); ?>
</p>

<?php echo form_close(); ?>

I'm using Codeigniter.我正在使用 Codeigniter。

You're missing a semicolon after your textarea.您在 textarea 之后缺少一个分号。

Not sure that that's the problem, but...不确定这是不是问题,但是...


PS If you're anyhow using CI's form helper, why don't you use it for the input's as well? PS 如果您无论如何都在使用 CI 的表单助手,为什么不将它也用于输入呢?

Instead of:代替:

<input id="info_id" type="hidden" name="info_id" value="<?php echo $info[0]->id;?>">

write:写:

<?php echo form_hidden('info_id', $info[0]->id, 'id="info_id"'); ?>

that way it's much cleaner, and easier to read.这样它更干净,更容易阅读。

Not sure where your problem is.不知道你的问题出在哪里。
1st, shouldn't your input tag be closed, ie a slash at the end:第一,您的输入标签不应该被关闭,即末尾的斜杠:

<input id="info_id" type="hidden" name="info_id" value="<?php echo $info[0]->id;?>" />

Then, what's happening if you try to display it?那么,如果您尝试显示它会发生什么?

<input id="info_id" type="text" name="info_id" value="<?php echo $info[0]->id;?>" />

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM