我有一个根据用户输入动态生成的表单。
最初向用户显示 3 个可供选择的字段(日期开始、日期到和音高类型(,他们选择他们的选项,单击提交,脚本会生成一个表格,其中包含范围内每个日期的输入供他们编辑。
生成的表单示例如下:
<table id="avtable">
<thead>
<tr>
<th>Date</th>
<th>Current bookings</th>
<th>Max bookings</th>
</tr>
</thead>
<tbody>
<form action="index.php?page=availability&task=edit&action=submit" method="post"></form>
<input type="hidden" name="pitchtype" value="1" />
<tr>
<td>2012-05-13</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="max"></td>
</tr>
<tr>
<td>2012-05-14</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="max"></td>
</tr>
<input type="submit" value="Save" name="Submit" />
</form>
</tbody>
</table>
在接收PHP文件中,我需要能够处理每个日期的数据,并且不知道从哪里开始!通常,如果它是一个静态形式,我只会使用类似的东西
$max = $_REQUEST['max'];
获取编辑的字段。
显然,我需要做的是将每个编辑的字段与其日期配对,以便我像往常一样处理数据。我想我需要某种带有表单数据数组的 php 循环,但我不太确定从哪里开始......有什么想法吗?
编辑:
我认为我需要将输出的表单编辑为这样的内容,因此每个输入的名称与日期列相同,因此我需要知道的是如何获取接收 php 文件中的所有日期:
<table id="avtable">
<thead>
<tr>
<th>Date</th>
<th>Current bookings</th>
<th>Max bookings</th>
</tr>
</thead>
<tbody>
<form action="index.php?page=availability&task=edit&action=submit" method="post"></form>
<input type="hidden" name="pitchtype" value="1" />
<tr>
<td>2012-05-13</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="2012-05-13"></td>
</tr>
<tr>
<td>2012-05-14</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="2012-05-14"></td>
</tr>
<input type="submit" value="Save" name="Submit" />
</form>
</tbody>
</table>
非常感谢!
凯文
为了首先传递信息,您需要为文本输入的不同名称指定如下:
<table id="avtable">
<thead>
<tr>
<th>Date</th>
<th>Current bookings</th>
<th>Max bookings</th>
</tr>
</thead>
<tbody>
<form action="index.php?page=availability&task=edit&action=submit" method="post"></form>
<tr>
<td>2012-05-13</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="SpinMax"></td>
</tr>
<tr>
<td>2012-05-14</td>
<td>0</td>
<td><input type="text" value="10" class="spinner" maxlength="3" name="SpinMax2"></td>
</tr>
<input type="submit" value="Save" name="Submit" />
</form>
</tbody>
</table>
从那里开始,你的PHP脚本应该是这样的:
$SpinMax = $_POST["SpinMax"];
$SpinMax2 = $_POST["SpinMax2"];
通过使用 $_POST,您可以根据您在文本区域中给出的"名称"来分配 PHP 变量。