多くのドロップダウン ボックスを持つフォームに取り組んでおり、データベースからドロップダウンの値を取得しています。すべてが完璧に進んでいますが、送信ボタンを 1 つ追加したいと思います。フォームを送信すると、選択したドロップダウン値とその ID を取得したいと考えています。その方法がわかりません。これで私を助けてください。
前もって感謝します。
これが私のコードです-
<!DOCTYPE html>
<html>
<?php
$db = JFactory::getDBO();
?>
<head>
<script>
var showClasses = {
};
function fnchecked(blnchecked,className)
{
if(blnchecked)
{
showClasses[className] = true;
}
else
{
showClasses[className] = false;
}
var ps = document.getElementById("div-block").children;
var psNumber = ps.length;
for (var i = 0; i < psNumber; i ++) {
var have = hasClasses(ps[i], showClasses);
if (have) {
ps[i].style.display = "";
} else {
ps[i].style.display = "none";
}
}
}
function hasClasses(element) {
var result = false;
for (var cls in showClasses) {
if (showClasses[cls]) {
if ((' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1) {
result = true;
}
}
}
return result
}
</script>
</head>
<body>
<form name="shohide1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div>
<label>Technologies: </label></br>
<input type="checkbox" name="technologies1" onChange="fnchecked(this.checked,'question1');" /> Kingspan Solar</br>
<input type="checkbox" name="technologies2" onChange="fnchecked(this.checked,'question2');" /> Solar PVT</br>
<input type="checkbox" name="technologies3" onChange="fnchecked(this.checked,'question3');" /> Insulation</br>
<input type="checkbox" name="technologies4" onChange="fnchecked(this.checked,'question4');" /> Gas boiler</br>
<input type="checkbox" name="technologies5" onChange="fnchecked(this.checked,'question5');" /> Oil boiler</br>
<input type="checkbox" name="technologies6" onChange="fnchecked(this.checked,'question6');" /> Heat recovery ventilation</br>
<input type="submit" name="formSubmit" value="Get The Info">
<div id="div-block" >
<p class=" question1 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=1';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 question3 question4 question5 question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=2';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=3';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class="question1 question2 question3 question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=4';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question2 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=5';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question3 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=6';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question3 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=7';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=8';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=9';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question4 question5 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=10';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
<p class=" question6 " style="display: none">
<?php
$query = $db->getQuery(true);
$query = 'select a.question, b.answer from #__questions As a RIGHT JOIN #__answers As b ON a.id = b.question_id where b.question_id=11';
$db->setQuery((string)$query);
$results = $db->loadObjectList();
if ($results)
{
print_r($results['0']->question);
echo '<select>';
echo '<option value="">Click & Choose</option>';
foreach($results as $result)
{
echo '<option value="'.$result->answer.'">'.$result->answer.'</option>';
}
echo '</select>';
}
?>
</p>
</div>
</div>
</body>
</html>