[英]How to post radio button value false/0, if radio button option is not selected & set true/1, if value is selected in the form of array?
[英]Cannot retrieve selected radio button value in PHP form post
我無法在表單中獲取所選的單選按鈕值。 無論選擇哪個選項,我都將獲得“ on”值。 請注意,這是在“ WordPress插件選項”頁面中。
表單代碼如下:
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>Title</h2>
<br />
<form action="options-general.php?page=page" method="post">
<table class="widefat">
<thead>
<tr>
<th></th>
<th>Site Name</th>
<th>Site URL</th>
<th>Username</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Site Name</th>
<th>Site URL</th>
<th>Username</th>
</tr>
</tfoot>
<tbody>
<?php
$size = count($sites);
for ( $i = 0; $i < $size; $i++) {
echo '<tr>';
for ($j = 0; $j < 4; $j++) {
if ($j == 0) {
echo '<td><input type="radio" id="cta_siteID_'.$i.'" name="cta_siteID",value="'.$i.'"/></td>';
}
else
{
echo '<td>'.$sites[$i][$j-1].'</td>';
}
}
echo '</tr>';
}
?>
</tbody>
</table>
<br />
<input type="hidden" name="formType" value="main" />
<select name="selectedItem">
<option value="" selected="true">Select an Option</option>
<option value="add">Add Site</option>
<option value="edit">Edit Site</option>
<option value="delete">Delete Site</option>
</select>
<input type="submit" name="Apply" value="Apply" class="button-primary" />
</form>
</div>
在單選組中選擇一個項目后執行var_dump($ _ POST)時,我得到以下信息:
onarray(4){[“ cta_siteID”] => string(2)“ on” [“ formType”] => string(4)“ main” [“ selectedItem”] => string(4)“ edit” [“ Apply “] => string(5)”應用“}
在發布表單之前,這些值已在HTML中正確呈現,不確定發生了什么。
無論我選擇哪個單選選項,“ on”值都會顯示,並且如果未選擇任何選項,則根本不會顯示(正如我期望的那樣)。
輸入標簽中不應包含逗號:
name="cta_siteID",value=
這很可能導致您的瀏覽器無法識別所傳遞的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.