我有一个问题,希望要求初学者并不是太多。它基本上是一个下拉框,让您选择汽车并将您的名字提交到列表中。稍后我将添加删除功能以及代码清理。
它是什么:它是一个下拉<select>
表单,可让您选择<option>
。我正在尝试让表单将所选的<option>
和登录用户的名称提交给一个数组,如下所示:
entries =>
0 =>
string 'Mercedes SLS AMG GT3' (length=20) <- the <option> chosen
string 'John Doe' (length=20) <- the user's name
1 =>
string 'Audi GT3' (length=20) <- the <option> chosen
string 'Peter Smith' (length=20) <- the user's name
等...
我有一个高级自定义字段设置(从另一个节点类型引用),作为<select><option>
列表。
如果您不想阅读以下内容,请使用Pastebin:http://pastebin.com/Hd1kiHxm
!!非常感谢那些希望帮助一个爱好项目的菜鸟的人!
以下代码:
<!-- Series Cars Stuff -->
<?php
$posts = get_field('series_cars_reference');
if( $posts ): ?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<form name="choose_car" method="POST" action="">
<?php
$rows = get_field('cars');
if($rows) {
echo '<select name="cars">';
foreach($rows as $row)
{
echo '<option name="cars" value="' . $row['car'] . '">' . $row['car'] . '</option>';
}
echo '</select>';
echo '<input type="submit" name="submit" value="Submit"/>';
}
$current_user = $current_user->display_name;
$selectOption = Array(
'entry' => array(
'name' => $current_user,
'car' => $_POST['cars'],
));
echo '<pre>'; print_r($selectOption);echo '</pre>';
if(isset($_POST['submit'])){
add_post_meta( get_the_ID(), 'entries', $selectOption );
}
?>
</form>
<!-- SHOW ALL POST DATA - VAR DUMP PRINT -->
<h3>All Post Meta</h3>
<?php $getPostCustom=get_post_custom(); // Get all the data ?>
<?php
foreach($getPostCustom as $name=>$value) {
echo "<strong>".$name."</strong>"." => ";
foreach($value as $nameAr=>$valueAr) {
echo "<br /> ";
echo $nameAr." => ";
echo var_dump($valueAr);
}
echo "<br /><br />";
}
?>
//以下是输出打印VAR看起来像的东西:
entries =>
0 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
1 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
2 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
3 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
4 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
5 =>