<h3>Add a vehicle</h3>
<form action="" method="post" enctype="multipart/form-data" >
<b>VIN: <input type="text" name="vin">
<button class="btn-success"><a style="color: white;" href="#">Decode Vin</a></button><br />
Year: <?php include 'admin/tool/caryears.php'; ?>
Make: <?php include 'admin/tool/carmakes.php'; ?>
Model: <input type="text" name="model"><br />
Mileage: <input type="text" name="mileage"><br />
Price: <input type="text" name="price"><br />
VIN: <input type="text" name="vin"><br />
Attribute: <input type="text" name="att1">
Attribute: <input type="text" name="att2"><br />
Attribute: <input type="text" name="att3">
Attribute: <input type="text" name="att4"><br />
<table border="1" bordercolor="FFCC00" style="background-color:FFFFCC" width="100%" cellpadding="3" cellspacing="3">
<center>
<b>Common Attributes</b>
<tr>
<th>Body style</th>
<td>SUV <input value="suv" name="bodystyle" type="radio"></td>
<td>Sedan <input value="sedan" name="bodystyle" type="radio"></td>
<td>Truck <input value="truck" name="bodystyle" type="radio"></td>
<td>Mini Van <input value="minivan" name="bodystyle" type="radio"></td>
<td>Convertible <input value="convertible" name="bodystyle" type="radio"></td>
<td>Coupe <input value="coupe" name="bodystyle" type="radio"></td>
</tr><tr><td></td>
<td>Hatchback <input value="hatchback" name="bodystyle" type="radio"></td>
<td>Hybrid <input value="hybrid" name="bodystyle" type="radio"></td>
<td>Diesel <input value="diesel" name="bodystyle" type="radio"></td>
<td>Crossover <input value="crossover" name="bodystyle" type="radio"></td>
</tr>
<tr>
<th>Engine and Performance</th>
<td>Engine Size <input name="enginesize" type="text" value=" L" class="input-small"></td>
<td>Cylinders <select name="cyl" class="input-small"><option>Select</option><?php $i=2; while($i<13){echo '<option value="cyl'.$i.'">'.$i.' Cylinders</option>'; $i++;}?></select></td>
<td>Horse Power <input name="hp" class="input-small" type="text"></td>
<td>Diesel <input value="diesel" name="fuel" type="radio"></td>
<td>Gasoline <input value="gasoline" name="fuel" type="radio"></td>
</tr>
<tr>
<tr>
<th>Transmission</th>
<td>Automatic <input value="automatic" name="transmission" type="radio"></td>
<td>Manual <input value="manual" name="transmission" type="radio"></td>
<td>4 Speed <input value="fourspeed" name="shifts" type="radio"></td>
<td>5 Speed <input value="fivespeed" name="shifts" type="radio"></td>
<td>6 Speed <input value="sixspeed" name="shifts" type="radio"></td>
<td>OverDrive <input name="od" type="checkbox"></td>
</tr>
<tr>
<th>Sound System</th>
<td>CD Player <input value="cd" name="sound" type="radio"></td>
<td>MP3 Player <input value="mp3" name="sound" type="radio"></td>
<td>DVD Player <input value="dvd" name="sound" type="radio"></td>
<td>GPS Nav <input name="gps" type="checkbox"></td>
<td>Brand: <input name="sound_system" type="text" class="input-small"></td>
<td>Satellite Radio <input name="sradio" type="checkbox"></td>
</tr>
<tr>
<th>Instrumentation</th>
<td>Tachometer <input name="tachometer" type="checkbox"></td>
<td>Clock <input name="clock" type="checkbox"></td>
<td>Trip Computer <input name="trip" type="checkbox"></td>
<td>Exterior-Weather <input name="eweather" type="checkbox"></td>
<td>All-Digital <input name="digitalboard" type="checkbox"></td>
</tr>
<tr>
<th>DriveTrain</th>
<td>Rear-wheel-drive <input value="rwd" name="drive" type="radio"></td>
<td>Front-wheel-drive <input value="fwd" name="drive" type="radio"></td>
<td>All-wheel-drive <input value="awd" name="drive" type="radio"></td>
<td>4x4 <input name="fxf" type="checkbox"></td>
<td>Cruise Control <input name="cruisecontrol" type="checkbox"></td>
<td>Tilt Steering <input name="tiltsteering" type="checkbox"></td>
</tr>
<tr>
<th>Inside and outside</th>
<td>A/C <input name="ac" type="checkbox"></td>
<td>Removable Top <input name="removabletop" type="checkbox"></td>
<td>Keyless <input name="keyless" type="checkbox"></td>
<td>AirBags <input name="airbags" type="checkbox"></td>
<td>Alloy Wheels <input name="alloy" type="checkbox"></td>
<td>Trunk anti-trap <input name="trunkantitrap" type="checkbox"></td>
</tr>
<tr>
<th>Electric Powered Options</th>
<td>Power Windows <input name="ewindows" type="checkbox"></td>
<td>Power Mirrors <input name="emirrors" type="checkbox"></td>
<td>Power Driver Seat <input name="eseat" type="checkbox"></td>
<td>Power Locks <input name="elocks" type="checkbox"></td>
<td>Vehicle Anti-theft <input name="antitheft" type="checkbox"></td>
<td>LED headlights <input name="ledheadlights" type="checkbox"></td>
</tr>
</table>
</form>
所以我需要检查每一个,如果它不为空或检查或选择,那么创建一个数组。
我个人认为我做错了什么,有没有更好的方法来解决这个问题?
我基本上需要这些信息才能将其输入属性数据库</ p>
答案 0 :(得分:1)
如果您希望捕获checkbox
输入的值,那么您可以使用PHP来实现它。您希望复选框输入具有相同的名称,但在末尾添加方括号[]
。提交表单并检查具有相同名称的复选框字段的值后,您将获得一个包含已检查选项的数组。
我的简化示例:
HTML 的
<form method="post">
<label for="power-windows">Power Windows</label>
<input type="checkbox" id="power-windows" name="e-power-opts[]" value="power windows" />
<br>
<label for="power-doors">Power Doors</label>
<input type="checkbox" id="power-doors" name="e-power-opts[]" value="power doors" />
<br>
<label for="power-locks">Power Locks</label>
<input type="checkbox" id="power-locks" name="e-power-opts[]" value="power locks" />
<input type="submit" name="submit" value="submit">
</form>
通过上面的示例,我们假设用户选择了Power Windows
和Power Doors
。当您检查$_POST['e-power-opts']
的内容时,您将收到如下数组:
Array
(
[0] => power windows
[1] => power doors
)
如果未选择任何选项,则$_POST['e-power-opts'] = null
。
您可以遍历$_POST
但如果没有为checkbox
或radio
输入选择任何内容,则$_POST
中不会有相应的“空”值。例如,您在表单中有make
,model
和electronic power options
,并且用户没有为electronic power options
复选框选择任何内容。您的$_POST
内容与此类似:
Array
(
[make] => pontiac,
[model] => g6,
[submit] => submit
)
请注意electronic power options
没有键值对。如果您需要在数据库插入之前设置默认值,我只会指出这一点。
最后,大多数时候你需要检查每个字段。不只是为了看它们是否为空,而且还用于验证/消毒目的。
您可能还想查看PHP过滤器功能:http://www.php.net/manual/en/ref.filter.php。