douzaipou3327 2014-07-17 09:33
浏览 56
已采纳

PHP / Mysql表单带有更多复选框,其中一些弹出式问题重复出现

Hi there i have a form (with specific id) that has checkboxes in it and when the checkbox is clicked, more questions (basicly a text field) will pop up. However some checkboxes have the same questions inside. Then I am saving the data to a mysql database. And i am displaying it afterwards. And the Question is: How to create some sort of switch statement or some algorithm that it would post in the current id and only to desired textfield.

Fo illustration:

0-100kg (Checkbox1)

- Which material? (textfield with name=material)

- Circle radius? (textfield with name=radius)

100-500kg (Checkbox2)

- Which material? (textfield with name=material)

- Circle radius? (textfield with name=radius)

500-1000kg (Checkbox3)

- Which material? (textfield with name=material)

- Circle radius? (textfield with name=radius)

- Roots? (textfield with name=roots)

Code:

Form:

<label class="collapse" for="100to500"><b>100 - 500kg</b></label>
<input id="100to500" type="checkbox" name="100to500">
<div><br>
Which material? <input type="text" name="material"/><br>
Circle radius? <input type="text" name="radius"/><br></div>

<label class="collapse" for="500to1000"><b>500 - 1000kg</b></label>
<input id="500to1000" type="checkbox" name="500to1000">
<div><br>
Which material? <input type="text" name="material"/><br>
Circle radius? <input type="text" name="radius"/><br>
Roots? <input type="text" name="roots"/><br></div>

PHP:

storing variables:

$material=mysql_real_escape_string($_POST['material']);
$radius=mysql_real_escape_string($_POST['radius']);
$roots=mysql_real_escape_string($_POST['roots']);

$100to500 = isset($_POST['100to500']) ? $_POST['100to500'] : '0';
$500to1000= isset($_POST['500to1000']) ? $_POST['500to1000'] : '0';

I am trying to accopmlish that it would somehow save all the data into same id (database row) and save only the clicked on / filled data. I know it is a silly explanation but i am using PHP for 2 weeks only so im a complete noob :)

Thank you.

  • 写回答

1条回答 默认 最新

  • ds20021205 2014-07-17 09:56
    关注

    First, I assume you would not allow multiple section of weight categories? In that case use a select tag to limit user input. secondly set you layout so that it looks like this

    [dropdown list/ select]
    - Which material? (textfield with name=material)
    - Circle radius? (textfield with name=radius)
    - Roots? (textfield with name=roots)
    - Q4 e.t.c.
    

    filter all your possible question for every weight categories and make a list of all UNIQUE questions.

    then lastly, use javascript to show/hide each of the question according to the currently selected weight. it is possible to use php to "dynamically" change the UI of a webpage, but it is kinda silly and is way less efficent than javascript.

    The result form will be very easy to extract info from and won't give any possible duplicate textfield id/name

    here's a mini sample: http://jsfiddle.net/Nn4zR/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!