【发布时间】:2009-07-16 14:36:32
【问题描述】:
我在查看页面中创建了一个输入字段,例如
<div class="input text">
<label for="2">First Name (required) </label>
<input type="text" value="" style="width: 300px;" id="2" class="required" name="First Name"/>
</div>
<div class="input text">
<label for="5">Emailid</label>
<input type="text" value="" style="width: 300px;" id="5" name="Emailid"/><
/div>
<div class="input text">
<label for="6">Mobile Number</label>
<input type="text" value="" style="width: 30px;" id="6" name="Mobile Number"/>
<input type="text" value="" style="width: 30px;" id="6-1" name="Mobile Number"/>
<input type="text" value="" style="width: 70px;" id="6-2" name="Mobile Number"/>
</div>
这些都是在页面中生成的。我正在使用 CakePHp 控制器从该页面中检索内容值
foreach ($_POST as $key => $value):
echo $key;echo $value;
endforeach;
对于上述所有领域,我得到了正确的答案,例如 First_Name=A&Emailid=aruna@tcs.com&Mobile_Number=3
但是对于我的手机号码字段,我得到了最后一个 id 的值,例如 6-2。为什么会这样。?如何检索三个字段(6,6-1,6-2)中给出的手机号码的完整值?请建议我。
编辑:
foreach ($_POST as $key => $value):
$mobile_number = implode('', $_POST['number']);
echo $mobile_number;
$this->data['Result']['form_id']=$formid;
$this->data['Result']['label']=Inflector::humanize($key);
$this->data['Result']['value']=$value;
$this->Form->submitForm($this->data);
endforeach;
我正在使用上面的方法保存键及其值(即,控制器不知道填充页面中的所有字段是什么)。填充页可能/可能不包含电话号码字段。我如何确保页面具有电话号码字段并使用其键保存其值。
注意:$key 是 Fieldname,$value 是我的 field 值。只有 Phonenumber 字段的值是数组,在所有其他情况下它只是一个值。
【问题讨论】:
-
首先,您应该使用 Cake 方法来创建表单,并使用 Cake
$this->data变量来处理结果。到目前为止,这段代码没有任何内容。