У меня есть форма, которую я запускаю через checkbox.php и внедряю флажки в строку и возвращаю через URL.
Форма здесь:
<form action="checkbox.php" method="post">
<span class="gamma widget-title">YEAR</span><br />
<input type='checkbox' name='product_year[]' value="1970s" <?php echo ($_GET['product_cat'] == '1970s') ? ' checked "' : ''; ?>>1970s<br />
<input type='checkbox' name='product_year[]' value="1980s" <?php echo ($_GET['product_cat'] == '1980s') ? ' checked "' : ''; ?>>1980s<br />
<input type='checkbox' name='product_year[]' value="1990s" <?php echo ($_GET['product_cat'] == '1990s') ? ' checked "' : ''; ?>>1990s<br /><br />
<span class="gamma widget-title">PRODUCT</span><br />
<input type='checkbox' name='product_type[]' value="cards" <?php echo ($_GET['product_cat'] == 'cards') ? ' checked "' : ''; ?>>Cards<br />
<input type='checkbox' name='product_type[]' value="frames" <?php echo ($_GET['product_cat'] == 'frames') ? ' checked "' : ''; ?>>Frames<br /><br />
<span class="gamma widget-title">OCCASION</span><br />
<input type='checkbox' name='product_occasion[]' value="birthday" <?php echo ($_GET['product_cat'] == 'birthday') ? ' checked "' : ''; ?>>Birthday<br />
<input type='checkbox' name='product_occasion[]' value="anniversary" <?php echo ($_GET['product_cat'] == 'anniversary') ? ' checked "' : ''; ?>>Anniversary<br />
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset"><br><br>
</form>
А вот checkbox.php
$product_year = $_POST['product_year'];
$product_type = $_POST['product_type'];
$product_occasion = $_POST['product_occasion'];
if (isset ($product_year) && !isset($product_type) && !isset($product_occasion) ) {
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$product_year);
header('Location:'. $url);
exit;
}
else if (isset ($product_type) && !isset($product_year) && !isset($product_occasion) ) {
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$product_type);
header('Location:'. $url);
exit;
}
else if (isset ($product_occasion) && !isset($product_year) && !isset($product_type) ) {
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$product_occasion);
header('Location:'. $url);
exit;
}
else if (isset ($product_year) && isset($product_type) && !isset( $product_occasion) ) {
$merged = array_merge($product_year, $product_type);
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$merged);
header('Location:'. $url);
exit;
}
else if (isset ($product_type) && isset($product_occasion) && !isset( $product_year) ) {
$merged = array_merge($product_type, $product_occasion);
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$merged);
header('Location:'. $url);
exit;
}
else if (isset ($product_year) && isset($product_occasion) && !isset( $product_type) ) {
$merged = array_merge($product_year, $product_occasion);
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$merged);
header('Location:'. $url);
exit;
}
else if (!isset ($product_year) && !isset($product_type) && !isset($product_occasion) ) {
$msg = "Please make a selection";
$url = 'http://localhost/yy-search-test/?msg';
header('Location:'. $url);
exit;
}
else {
$merged = array_merge($product_year, $product_occasion, $product_type);
$url = 'http://localhost/yy-search-test/?product_cat=' . implode( ',' ,$merged);
header('Location:'. $url);
exit;
}
Все работает хорошо, но я хочу повторно выбрать флажки на основе строки вывода из URL.
Это прекрасно работает, когда я выбираю 1 категорию, скажем, 1970-е годы, тогда как правило соблюдается.
Проблема у меня возникает, когда я выбираю 2 категории.Итак, == 1970-е годы не совпадают, как пример строки? Product_cat = 1970-е, карты.
Я пробовал несколько вещей, таких как взрыв строк в массиве, но я не могу заставить его работать.
Кто-нибудь может помочь?
Спасибо, Джейми