我有一个Wordpress循环,我已经从中构建了一个动态表单,我现在如何获取所有表单数据并发送它?
$items = array();
$queryBasket = "SELECT * FROM baskets";
$gotBasket = $connect->query($queryBasket);
while ($basket = $gotBasket->fetch_assoc()) {
//echo $basket['item'];
$items[] = $basket['item'];
}
$args = array(
'post_type' => array('product' ),
'order' => 'ASC',
'orderby' => 'title',
'post__in' => $items
);
$loop = new WP_Query($args);
$i = 0;
if ( $loop->have_posts() ) {
echo '<ul id="basket" class="row">';
while ( $loop->have_posts() ) {
$loop->the_post();
$i++;
?>
<li class="col-sm-12">
<a href="<?php echo bloginfo('url'); ?>/my-quotes/?del=<?php echo the_id(); ?>">x </a>
<a href="<?php echo the_permalink(); ?>" class="item-name"><?php the_title(); ?></a>
Quantity: <input type="number" name="item-<?php echo $i; ?>-count" id="item-<?php echo $i; ?>-count" class="item-count"/>
<input type="hidden" name="item-<?php echo $i; ?>-name" id="item-<?php echo $i; ?>-name" value="<?php the_title(); ?>">
<?php }
echo '</ul>';
} else {
}
wp_reset_postdata();
?>
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
答案 0 :(得分:0)
使它成为一个数组:
name="item[<?php echo $i; ?>][name]"
然后你可以迭代它
foreach ($_POST['item'] as $i => $values) {
echo "Name for $i: " . $values['name'];.
}