[英]adding html in values of a form
我試圖通過POST方法將html作為值傳遞給每個帖子。 變量/自定義字段“ tech_specs”包含一個html表:
<table>
<tbody>
<tr>
<td style>.....</td>
<td style>...</td>
</tr>
<tr>
<td style>....</td>
<td>....</td>
</tr>
</tbody>
</table>
表格獲取
echo "<form method='post' action='.../comparison-page/' >";
while (have_posts()) : the_post();
$my_id= get_the_ID();
$tech_spec = get_post_meta($my_id, 'tech_specs');
echo "<input type='checkbox' name=\"comparison[".$i_meta."]\" value=\"".$tech_spec."\" />";
$i_meta++;
endwhile;
echo "<input type='submit' name='submit' value='Submit'/>";
echo "</form>";
如圖所示,在復選框中的html值是value =“ Array”。 我面臨的問題是“數組到字符串的轉換”。 如何傳輸值(每個值的html表),以便可以通過表比較在另一個頁面中解析它們?
您可以在代碼中添加print_r來查看變量$ tech_spec中的內容,
$tech_spec = get_post_meta(get_the_ID(), 'tech_specs');
print_r($tech_spec);
//will return something like these :
//Array ( [key_1] => Array ( [0] => value_1 ), [key_2] => Array ( [0] => value_2 ) )
從數組$ tech_spec中提取所需的內容。
在您的回聲中,您可以輸入以下內容:
echo "<input type='checkbox' name=\"comparison[".$i_meta."]\" value=\"".$tech_spec['key_1']."\" />";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.