我有一个关于使用codeigniter进行表单验证的问题。用户按下“提交”按钮后,他们会收到预期的错误消息,但我也收到错误消息(如下)。显示错误消息的值将被隐藏。我不相信这是罪魁祸首,因为我尝试了语法而没有隐藏值而且它不起作用。我究竟做错了什么?谢谢大家。
错误消息
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: id
Filename: views/view_information.php
Line Number: 46
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: year
Filename: views/view_information.php
Line Number: 48
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: make
Filename: views/view_information.php
Line Number: 49
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: model
Filename: views/view_information.php
Line Number: 50
我的观点
<style type="text/css" media="screen">
label{display: block}
</style>
<?php
echo (isset($error)) ? $error : "";
if(isset($carprices) && !is_null($carprices))
{
echo "Car# " . $carprices[0]->id . "<br />";
foreach ($carprices as $prices)
{
echo 'ID Of Vehicle: '.$prices->id.'<br>';
echo 'Year: '.$prices->year.'<br>';
echo 'Make: '.$prices->make.'<br>';
echo 'Model: '.$prices->model.'<br>';
echo '<hr>';
$id = $prices->id;
$year = $prices->year;
$make = $prices->make;
$model = $prices->model;
echo "$id".'<br>';
}
}
/*
foreach($updateprices as $row){
$id = $row->id;
$year = $row->year;
$make = $row->make;
$model = $row->model;
}
*/
echo form_open('site/form_validate_cars');
echo validation_errors();
$data = array(
'cardescription_id' => "$id",
'caruser_id' => "5", // hard-coded in
'year' => "$year",
'make' => "$make",
'model' => "$model"
);
echo form_hidden($data);
echo form_label('Value:','value');
$data = array(
'name' => 'value',
'id' => 'value',
'value' => set_value('value')
);
echo form_input($data);
// -----------------
echo form_label('Exterior Color:','exterior_color');
$data = array(
'name' => 'exterior_color',
'id' => 'exterior_color',
'value' => set_value('exterior_color')
);
echo form_input($data);
// -----------------
echo form_label('Interior Color', 'interior_color');
$data = array(
'name' => 'interior_color',
'id' => 'interior_color',
'value' => set_value('interior_color')
);
echo form_input($data);
// -----------------
echo form_label('Mileage:','mileage');
$data = array(
'name' => 'mileage',
'id' => 'mileage',
'value' => set_value('mileage')
);
echo form_input($data);
// -----------------
// removed echo-only <tr>s on fuel type, state and transmission
// -----------------
echo form_label('State:','state');
$data = array(
'Texas' => 'Texas',
'California' => 'California',
'Florida' => 'Florida',
'Nevada' => 'Nevada'
);
echo form_dropdown('State',$data,'California');
echo '<br>';
echo form_submit('SubmitDealerInfo','Submit!');
echo form_close();
?>
答案 0 :(得分:0)
不应该是这样吗?
foreach ($carprices as $prices)
{
echo 'ID Of Vehicle: '.$prices['id'].'<br>';
echo 'Year: '.$prices['year'].'<br>';
echo 'Make: '.$prices['make'].'<br>';
echo 'Model: '.$prices['model'].'<br>';
echo '<hr>';
$id = $prices['id'];
$year = $prices['year'];
$make = $prices['make'];
$model = $prices['model'];
echo "$id".'<br>';
}
答案 1 :(得分:0)
问题不在于codeigniter验证问题与您的代码有关 1 - 检查是否在验证错误时传递了所有变量 2 - 检查您的输入名称是否与验证名称相同。