2011-08-22 40 views
0

我與他們三人的提交表單來自具有不同ID的

他們兩個都還行,我用一個ID爲所有將成爲價值的提交表單值呼應提交

但一我現在掙扎的那些人當然是擁有所有不同價值觀的人,而選擇形式也有不同的ID,這讓我很難理解我如何迴應它。

<form action="" method="post"> 
    <div data-role="fieldcontain"> 
    <fieldset data-role="controlgroup" data-type="horizontal" > 
     <legend>เลือกช่อง</legend> 
      <input type="radio" name="radio-choice-1" id="radio-choice-1" value="ch41" checked="checked" /> 
      <label for="radio-choice-1">number 1</label> 

      <input type="radio" name="radio-choice-1" id="radio-choice-2" value="ch80" /> 
      <label for="radio-choice-2">number 2</label> 

      <input type="radio" name="radio-choice-1" id="radio-choice-3" value="ch44" /> 
      <label for="radio-choice-3>"number 3</label> 

      <input type="radio" name="radio-choice-1" id="radio-choice-4" value="ch42" /> 
      <label for="radio-choice-4">number 4</label> 

      <input type="radio" name="radio-choice-1" id="radio-choice-5" value="ch83" /> 
      <label for="radio-choice-5">number 5</label> 
    </fieldset> 
</div> 
</form> 

,這裏是什麼,我想呼應

<video width="5%" height="5%" src="http://mydomain:<?php echo $_POST["radio-choice-1"]; ?>-<?php echo $_POST["date"]; ?>-<?php echo $_POST["time"]; ?>" alt="" controls="" tabindex="0"> 

所以這個問題是關於"radio-choice-#"

因爲它的ID


5號這裏是例子

  <input type="radio" name="radio-choice-1" id="radio-choice-2" value="ch80" /> 
     <label for="radio-choice-2">number 2</label> 

     <input type="radio" name="radio-choice-1" id="radio-choice-3" value="ch44" /> 
     <label for="radio-choice-3>"number 3</label> 

     <input type="radio" name="radio-choice-1" id="radio-choice-4" value="ch42" /> 
     <label for="radio-choice-4">number 4</label> 

     <input type="radio" name="radio-choice-1" id="radio-choice-5" value="ch83" /> 
     <label for="radio-choice-5">number 5</label> 

所以,如果他們選擇菜單編號5

我想在這裏呼應

<video width="5%" height="5%" src="http://mydomain:<?php echo $_POST["the value of number 5"]; ?"> 
+3

我注意到了兩件事:1)你錯過了3號和2號關閉'>')你在所有單選按鈕上定義了兩次名稱和id屬性。而且,一個特定的ID只能在句法上使用* once。您不能定義一個分區和五個單選按鈕來使用相同的ID。 – animuson

+1

fyi,您在radio標籤3的'label'中缺少一個括號。 '

+0

@animuson對不起,我忘了發佈原來的;我發佈了一個和我一起玩的遊戲[我說過的那個] – Ali

回答

1

你的代碼實際上是從單選按鈕所獲得的價值已經是正確的。以下是您可以用來保持數據更有條理並能夠獲取您所在的「網頁」號碼的內容。

<?php 
$items = array('ch41', 'ch80', 'ch44', 'ch42', 'ch83'); 
$page = array_search((empty($_POST['choice']) ? 'ch41' : $_POST['choice']), $items) + 1; // Change 'ch41' to whatever the default page is 
// To name the labels, you can add keys for your values like so: 
$items = array('home' => 'ch41', 'page' => 'ch80', 'channel' => 'ch44', 'news' => 'ch42', 'contact' => 'ch83'); 
$page = (empty($_POST['choice']) ? 'home' : array_search($_POST['choice'], $items)); // Replace 'home' with whatever the default page is 
// Then replace the <?= $key + 1 ?> below with just <?= $key ?> 
?> 
You are currently on page <?= $page ?>. 
<form action="" method="post"> 
<div data-role="fieldcontain"> 
<fieldset data-role="controlgroup" data-type="horizontal" > 
    <legend>เลือกช่อง</legend> 
<?php foreach ($items as $key => $value): ?> 
     <input type="radio" name="choice" id="radio-choice-<?= $key ?>" value="<?= $value ?>"<?= $key === $_POST['choice'] ? ' checked="checked"' : '' ?> /> 
     <label for="radio-choice-<?= $key ?>">number <?= $key + 1 ?></label> 
<?php endforeach; ?> 
</fieldset> 
</div> 
</form> 

一個粗略的例子。您可以將其他通道添加到$items陣列。它將默認爲第1頁,並自動檢查您當前正在查看的頁面的單選按鈕。我希望這是你想要的。

+0

代碼工作完美,感謝你這麼多 快速的問題勒貝爾在<標籤=「無線電選擇 - 」>數<?= $鍵+ 1>我怎麼能名稱的標籤,而不是使用數字1,2,3,4,5別的東西像 家,頁面,頻道,新聞,接觸 – Ali

+1

我已經修改代碼ab OVE。如果使用該方法,還要刪除PHP輸出前面的'number'文本。 – animuson

+0

抱歉,也許我沒有讓我的評論明確上述 你給我的是完美的,但代碼,除了一兩件事,我試圖使標籤顯示像 <標籤=「無線電選擇 - 3>「首頁 <標籤=」無線電選擇 - 3>「頁 <標籤=」無線電選擇 - 3>「聯繫 – Ali