繁体   English   中英

在表单的值中添加html

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM