-1

I want to send the value from this form to the same page, but the submit button not send the value

This is the form:

<form method="post" action="">
        <select name="b" value="<?=isset($_POST['b']) ? CHtml::encode($_POST['b']) : '' ; ?>">

            <option value="1">Januari</option>
            <option value="2">Februari</option>
            <option value="3">Mac</option>
            <option value="4">April</option>
            <option value="5">Mei</option>
            <option value="6">Jun</option>
            <option value="7">Julai</option>
            <option value="8">Ogos</option>
            <option value="9">September</option>
            <option value="10">Oktober</option>
            <option value="11">November</option>
            <option value="12">Disember</option>               
        </select>
        <input type="submit" value="Papar Statistik" /><hr />
    </form>

This is the funtion that use to Get the data value from form above:

<?php 

if (isset($_GET['b']) && !empty($_GET['b']))
    $current_month = $_GET['b'];
else
    $month = date('Y-m-d', time());
    $bulan = strtotime($month); // FUNCTION CONVERSION DATE KEPADA DAY
    $current_month = date("m", $bulan);

    $teacher = Yii::app()->user->getId();
    $jumlahStatistik_hadir = 0;

    for ($d = 1; $d <= 30; $d++){

      $statistik_hadir = Detail::model()->countByAttributes(array(
            'status' => '1',
            'date' => '2015-'.$current_month.'-'.$d.'',
            'teacher_id' => $teacher));

      $jumlahStatistik_hadir = 
          ($jumlahStatistik_hadir+$statistik_hadir);
    }
    print_r ($jumlahStatistik_hadir);
?>
crafter
  • 6,246
  • 1
  • 34
  • 46
mrdidie
  • 35
  • 1
  • 8
  • 1
    I downvoted you for a number of reasons : Your issues is related to HTML and PHP, not Yii. The tags datepicker and yii-components have nothing to do with your issue you described, It may get you more attention, but does not reflect your true issue. Your code is badly formatted, which makes it difficult to read. You are even missing block brackets '{' and '}' in your if/else statements. Please take some time to make it easy for others to assist you, – crafter Jul 03 '15 at 09:08

2 Answers2

1

If you are sending your form data using POST method

<form method="post" action="">
    <select name="b">
        <option value="1">Januari</option>
        <option value="2">Februari</option>
    </select>
</form>

You can expect the PHP to provide the data in the $_POST global, not post.

// This is correct
echo $_POST['b'];
// This is not correct
echo $_GET['b'];

NOTE: Instead of using 'value' in your select tag.

   <select name="b" value="2">

You need to provide the selected option for the chosen value

<option value="1">Januari</option>
<option value="2" selected='selected'>Februari</option>
crafter
  • 6,246
  • 1
  • 34
  • 46
  • Now i have some problem, why when i choose another month, the result only show January ? @crafter – mrdidie Jul 06 '15 at 08:31
1

Why not in Yii Form

    <?php 
   $years=array(
    0 => '',
    1 => 'Januari',
    2 => 'Februari',
    3 => 'Mac',
    4 => 'April',
    5 => 'Mei',
    6 => 'Jun',
    7 => 'Julai',
    8 => 'Ogos',
    9 => 'September',
    10 => 'Oktober',
    11 => 'November',
    12 => 'Disember'
);
?>
<?php echo CHtml::beginForm();?>

<?php echo CHtml::dropDownList('b', (isset($_POST['b'])?$_POST['b']:$years[0]), $years);?>

<?php echo CHtml::submitButton('Paper Statistik')?> 

<?php echo CHtml::endForm();?>
Double H
  • 4,120
  • 1
  • 15
  • 26