alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/5801a98732e2e66f288b4568/option-radio-button-dan-check-box-fpdf
Option Radio Button dan Check Box FPDF
Selamat pagi On izin tanya,
Saya mencoba menggunakan FPDF dinamis dengan sumber yg di sini : http://fpdf.org/en/tutorial/tuto1.htm
Kode yang saya pakai yaitu :

Form.php :
Code:

<div class="container">
<form class="contact-us form-horizontal" action="123.php" method="post">
<legend>Percobaan FPDF</legend>

<div class="control-group">
<label control-label">Drop Down Option</label>
<div class="col-sm-8 input-group"><select name="dropdownselect" class="form-control1">
<option>--->Silahkan Pilih<---</option>
<option>Satu-1</option>
<option>Dua-2</option>
<option>Tiga-3</option>
<option>DLL</option>
</select></div>
</div>

<div class="form-group">
<label class="control-label">Radio Option</label>
<div class="col-sm-8 input-group">
<input type="radio" class="form-control1" name="radiobutonoption" >Option-1<br>
<input type="radio" class="form-control1" name="radiobutonoption" >Option-2<br>
<input type="radio" class="form-control1" name="radiobutonoption" >Option-3
</div>
</div>

<div class="form-group">
<label class="control-label">Check BOX</label>
<div class="col-sm-8 input-group">
<input type="checkbox" class="form-control1" name="checkbox">1.Tangan<br>
<input type="checkbox" class="form-control1" name="checkbox">2.Kaki<br>
<input type="checkbox" class="form-control1" name="checkbox">3.Pendengaran<br>
<input type="checkbox" class="form-control1" name="checkbox">4.Badan<br>
<input type="checkbox" class="form-control1" name="checkbox">5.Tidak Ada
</div>
</div>

<div class="control-group">
<label class="control-label">Input Text</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" class="input-xlarge" name="inputtext" placeholder="Testing">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Text Area</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-pencil"></i></span>
<textarea name="textarea" class="span4" rows="4" cols="80" placeholder="Testing"></textarea>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn">Cancel</button>
</div>
</div>
</form>
</div>


123.php
Code:

<?php
require('fpdf.php');
$dropdownselect=$_POST['dropdownselect'];
$radiobutonoption=$_POST['radiobutonoption'];
$checkbox=$_POST['checkbox'];
$inputtext=$_POST['inputtext'];
$textarea=$_POST['textarea'];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

echo "Drop Down Option : $dropdownselect<br>";
echo "Radio Option : $radiobutonoption<br>";
echo "Check Box Option : $checkbox<br>";
echo "Input Text : $inputtext<br>";
echo "Text Area : $textarea<br>";

$pdf->Output();
?>


Hasilnya :
Quote:
Drop Down Option : Tiga-3
Radio Option : on
Check Box Option : on
Input Text : sfjhdkjh
Text Area : jsdlkfjkl

Yaitu setiap pilihan untuk radio button dan check box selalu ON hasilnya, kira2 dmn salahnya yach Om agar bisa normal hasilnya misalnya :
Hasilnya :
Quote:
Drop Down Option : Tiga-3
Radio Option : Option-2
Check Box Option : 2.Kaki dan 5.Tidak Ada
Input Text : sfjhdkjh
Text Area : jsdlkfjkl


Terimakasih banyak atas bantuannya
Update :
1. Masalah hasilnya selalu ON sudah fix yg mana solusinya saya nambah value disetiap pilihannya,
2. Issue kedua yaitu dibagian check box, misal ada dua yang dipilih, yang muncul di hasil hanya pilihan yang terakhir,
Kode check box :
Code:

<div class="form-group">
<label class="control-label">Check BOX</label>
<div class="col-sm-8 input-group">
<input type="checkbox" class="form-control1" name="checkbox" value="1.Tangan" >1.Tangan<br>
<input type="checkbox" class="form-control1" name="checkbox" value="2.Kaki" >2.Kaki<br>
<input type="checkbox" class="form-control1" name="checkbox" value="3.Pendengaran" >3.Pendengaran<br>
<input type="checkbox" class="form-control1" name="checkbox" value="4.Badan" >4.Badan<br>
<input type="checkbox" class="form-control1" name="checkbox" value="5.Tidak Ada" >5.Tidak Ada
</div>
</div>

Misal saya pilih 2 dan 4, maka hasil yang muncul hanya pilihan yang terakhir yaitu 4, kira2 apa yg kurang yach om ?
Tambahan info sdh coba gini sama jg tetap pilihan yg terakhir diambil, ada saran kira2 Om ? :
Potongan dari form.php di atas
Code:

<div class="form-group">
<label class="control-label">Check BOX</label>
<div class="col-sm-8 input-group">
<input type="checkbox" class="form-control1" name="check_list[]" value="1.Tangan" >1.Tangan<br>
<input type="checkbox" class="form-control1" name="check_list[]" value="2.Kaki" >2.Kaki<br>
<input type="checkbox" class="form-control1" name="check_list[]" value="3.Pendengaran" >3.Pendengaran<br>
<input type="checkbox" class="form-control1" name="check_list[]" value="4.Badan" >4.Badan<br>
<input type="checkbox" class="form-control1" name="check_list[]" value="5.Tidak Ada" >5.Tidak Ada
</div>
</div>

123.php
Code:

<?php
require('fpdf.php');

$dropdownselect=$_POST['dropdownselect'];
$radiobutonoption=$_POST['radiobutonoption'];
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
$checkbox = "$check";
}
}
$inputtext=$_POST['inputtext'];
$textarea=$_POST['textarea'];

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

echo "Drop Down Option : $dropdownselect<br>";
echo "Radio Option : $radiobutonoption<br>";
echo "Check Box Option : $checkbox<br>";
echo "Input Text : $inputtext<br>";
echo "Text Area : $textarea<br>";

$pdf->Output();
?>


foreach($_POST['check_list'] as $check) {

$checkbox .= "$check";

}

lihat tanda "titik"? itu membuat $check baru ditambahkan ke $check lama. kalau gak, yang baru akan menimpa yg lama
Quote:Original Posted By nyzko
foreach($_POST['check_list'] as $check) {

$checkbox .= "$check";

}

lihat tanda "titik"? itu membuat $check baru ditambahkan ke $check lama. kalau gak, yang baru akan menimpa yg lama


Thanks om atas bantuannya,
Tapi saya coba, jadi dianggap blm dideklarasikan untuk $checkbox nya
Notice: Undefined variable: checkbox in /home/test/123.php on line 16
Ada saran Om ?
Thanks,
Solved, saya pakai echo implode(',', $_POST['check_list']);

Case closed