【发布时间】:2020-12-16 10:29:09
【问题描述】:
我有一个使用 post 方法提交更改的表单,我认为我没有很好地使用 isset 函数,因为在提交时我的页面上没有任何更改,我应该在我的页面上显示产品。
这是我的表格:
<form method="post" style="margin-left:5px; margin-right: 5px; margin-bottom: 10px;" name="myform">
<select size="1" onblur="this.size = 1" onchange="myform.submit();" class="form-control" id="filterText">
<option selected value="">Cat gories</option>
<option name="sofa" value="sofa">Canap s</option>
<option name="bed" value="bed">Lits</option>
</select>
</form>
这是在同一个文件的表单之后出现的 isset 条件:
if(isset($_POST["sofa"])){
$url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=fu003&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$products = json_decode($result, true);
curl_close($ch);
echo '<div id="wrap" class="wrap">';
foreach ($products['moreProducts']['productWindow'] as $items)
{
echo '<div class="bed_images" id="bed">';
echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs' . '/>';
echo '<h2 class="img_title">' . $items['name'] . '</h2>';
echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
echo '<p class="img_description">' . $items['typeName'] . '</p>';
echo '</div>';
}
echo '</div>';
} elseif (isset($_POST["bed"])){
$url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=bm003&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$products = json_decode($result, true);
curl_close($ch);
echo '<div id="wrap" class="wrap">';
foreach ($products['moreProducts']['productWindow'] as $items)
{
echo '<div class="bed_images" id="bed">';
echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs' . '/>';
echo '<h2 class="img_title">' . $items['name'] . '</h2>';
echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
echo '<p class="img_description">' . $items['typeName'] . '</p>';
echo '</div>';
}
echo '</div>';
} else {
$url="https://sik.search.blue.cdtapps.com/fr/fr/product-list-page/more-products?sessionId=22037cc5-f73c-4f71-a1d4-a90285da1789&category=fu001&sort=RELEVANCE&start=0&end=275&c=lf&v=20201118";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$products = json_decode($result, true);
curl_close($ch);
echo '<div id="wrap" class="wrap">';
foreach ($products['moreProducts']['productWindow'] as $items)
{
echo '<div class="bed_images" id="bed">';
echo '<img data-enlargeable class="images" src=' . $items['mainImageUrl'] . '?f=xxs' . '/>';
echo '<h2 class="img_title">' . $items['name'] . '</h2>';
echo '<p class="img_price">' . $items['priceNumeral'] . ' ^b ' . '</p>';
echo '<p class="img_description">' . $items['typeName'] . '</p>';
echo '</div>';
}
echo '</div>';
}
?>
else 条件得到验证,因为我的页面上一直显示最后一个 url 产品(表单提交之前和之后)所以我的问题是我认为我对 isset 条件的误解。
【问题讨论】:
-
我认为
<select>是表单的一部分。因此,选择名称(如果有的话)位于$_POST数组中,而不是其选项之一的名称。该值将是选定的值。