samedi 23 décembre 2017

Mutiple checkbox in php html

I have a form code html like this, but it's error for checkbox question, someone plase help my problem.

if(empty($tampil_pertanyaan)){
                echo "<tr><td colspan=\"6\">Data tidak tersedia</td></tr>";
    }else{
       $no = 1; //for question
       $no2 = 0; //for array
    foreach($tampil_pertanyaan as $row)
   {
    <tr>
        <td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]"  id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil1;?>"  oninput="this.className = ''"></td>
        <td> <?php echo $row->pil1;?></td>
    </tr>
    <tr>
        <td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]"  id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil2;?>" oninput="this.className = ''"></td>
        <td> <?php echo $row->pil2;?></td>
    </tr>
    <tr>
        <td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]"  id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil3;?>" oninput="this.className = ''"></td>
        <td> <?php echo $row->pil3;?></td>
    </tr>
    $no++;
    $no2++;
}

And i my controller (i use Codeigniter)

public function insert_jawaban(){
        // Proses pemvalidasian data yg di input
        $this->form_validation->set_rules('ket_jawaban[]', 'ket_jawaban', 'trim|xss_clean');
        if ($this->form_validation->run() == FALSE){
            echo validation_errors(); // tampilkan apabila ada error
        }else{

            //Insert ke tabel jawaban
            $result = array();
            foreach($_POST['ket_jawaban'] AS $key => $val){

                $result[] = array(
                    "id_jawaban"    => '',
                    "user"          => $_POST['user'][$key],
                    "ket_jawaban"   => $_POST['ket_jawaban'][$key],
                    "id_pilgan"     => $_POST['id_pilgan'][$key],
                    "id_pertanyaan" => $_POST['id_pertanyaan'][$key],
                    "id_survey"     => $_POST['id_survey'][$key],
                    "nama"          => $_POST['nama_user'][$key],
                    "unit"          => $_POST['unit_user'][$key],
                    "jenis"         => $_POST['jenis_user'][$key]
                );
            }

            $res = $this->db->insert_batch('jawaban', $result);
}

why every time I checked always only returns one value, even though I checked three.

before I apologize if there is any wrong in my question is because I am newbie here. Thanks and please be advised




vendredi 22 décembre 2017

How to edit data array to checkbox with javascript

Table Form HTML

 <table id="example3" class="display" cellspacing="0" width="100%">
      <thead>
         <tr>
           <th></th>
           <th>Nama</th>
           <th>Unit</th>
        </tr>
      </thead>
    </table>

Javascript to headle select row

$('#frm-example').on('submit', function(e){ //on submit
            var form = this;

           var rows_selected = table3.column(0).checkboxes.selected();

            // Iterate over all selected checkboxes
            $.each(rows_selected, function(index, rowId){
            // Create a hidden element 
                $(form).append(
                    $('<input>')
                    .attr('type', 'hidden')
                    .attr('name', 'id[]')
                    .val(rowId)
                );
            });

My database

+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
| id_survey | judul_survey | status_survey | id_target | id_kategori | responden | detail_target                | tgl_survey          |
+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
|       130 | tes          | terbit        |         3 |           2 |         2 | 198411162009101002,H76215021 | 2017-12-19 15:08:35 |
+-----------+--------------+---------------+-----------+-------------+-----------+------------------------------+---------------------+
1 row in set (0.07 sec)

Data checkbox in field detail_kategori, how i can put this into form checkbox for update?

Ok, i get code checkbox from here http://ift.tt/2dDLkF4 I want modify the code to edit




Pass database values to checkbox using JavaFX 8

I've looked everywhere to find how to pass SQLite database values to a checkbox. This is for computer software used on a desktop or laptop. I doubt my programming would help anyone help me. Does anyone have ANY ideas at all?




WordPress ACF Checkbox loop

I currently have a CPT of 'restaurant'. Each restaurant can have multiple 'features', chosen by the user in the back end via a ACF checkbox field.

I'd like to be able to loop through this field and apply a class name for each checkbox that is checked.

In the below example, the restaurant has 3 of the 4 possible fields ticked. However, only the 'Parking' icon is showing (4 times) - likely due to my if statements.

Ideally, i'd like it to loop through each 'if', grab the string attached to $feature_icon and then spit it out in the echo further below in the span.

I've tried moving the section of if statements to be within the 'foreach' loop to no avail.

Any advice appreciated, thanks.

<?php if( $featured_restaurants ): ?>
<?php foreach ( $featured_restaurants as $featured_restaurant ): ?>

<div class="card__inputs"> <!-- Featured card specific icons start -->

<?php
    if(in_array('alcohol', $restaurant_features)):
        $feature_icon = "Alcohol";
    endif;

    if(in_array('family_friendly', $restaurant_features)):
        $feature_icon = "Family-Friendly";
    endif;

    if(in_array('open_late', $restaurant_features)):
        $feature_icon = "Open-Late";
    endif;

    if(in_array('parking', $restaurant_features)):
        $feature_icon = "Parking";
    endif;
?>

    <div class="details u-float-left"> <!-- Featured card specific icons container start -->
    <span class="icon icon--medium icon--Italian"></span>
    <?php if($restaurant_features): ?>
        <?php foreach($restaurant_features as $restaurant_feature): ?>
            <span class="icon icon--medium icon--<?php echo $feature_icon; ?>"></span>
        <?php endforeach; ?>
    <?php endif; ?>

    </div> <!-- Featured card specific icons container end -->

    </div> <!-- Featured card specific icons end -->

<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>




How to utilize bootstrap toggle with flask

This question is an extension of this question regarding using the Bootstrap toggle with flask.

My code for the toggle is as follows:

<div class='media'>
                <div class='media-left'>
                  <div class='media-object'>
                    <div class='padding-right'>
                      <form action="/menu" method="post">
                        <input name="toggle" onclick="this.form.submit()" data-off="&lt;i class='fa fa-times'&gt;&lt;/i&gt; " data-on="&lt;i class='fa fa-check'&gt;&lt;/i&gt; " data-onstyle='success' data-size='large' data-style='ios' data-toggle='toggle' id='activate-toggle' type='checkbox' value="on">
                        <input name="toggle" type="hidden" value="off">
                      </form>
                    </div>
                  </div>
                </div>
                <div class='media-body'>
                  <div id='console-event'></div>
                </div>
              </div>

And my endpoint for the page is as follows:

    @app.route('/menu', methods=['POST', 'GET'])
def get_callback():
    if request.method == 'POST':
        button = request.form['toggle']
        print(button)
    return render_template('dashboard.html')

However I am not able to get any response from my button.

I am very lost at this point. I have tried to copy the format of the question above however I still cannot get the button to print or even use the POST method.

Here are my questions:

  1. How can I get a response from my button?
  2. How do I save the orientation so that when the user logs back in the button is how they previously left it?

(I am using SQLAlchemy if this is of any importance.)

Any help would be greatly appreciated!

Thank you,

Jonah




More MySQL rows

Hey For School I have to centralize my colleagues' absences I've been thinking about using the databases. I creates a html form and a table in phpMyAdmin, for school subjects I use Checkboxes as you can see in the image, but if I select 2 subjects in the database I have only one register with first subject which I selected first. Can you give me a MySQL query to register twice with same name but different subjects like:

William:English:unmotivated absence
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
William:Chemistry:unmotivated :absence

Look




JavaScript to change value of textbox

This code is for an unsubscribe form, where I need to toggle whether or not a checkbox is checked on initial start, and then change values based on a user's selection.

Basically, I'm passing a value into the html through our email platform. If the value is I, the checkbox should be checked and the value I. Conversely, if the value is O, the checkbox should not be checked and the value O.

For the data to be passed back into our email platform I have to use a hidden input to capture the value, otherwise it won't actually send the I or O back.

The JavaScript, which I have as a tag in the head (HTML Email)

var initValue = function() {
    var permStat = document.getElementById("emailPref").value
    if(permStat === "I"){
      document.getElementById("checkbox").checked = true;
    } else {
      document.getElementById("checkbox").checked = false;
    }
  }
  var changeValue = function(){
    var optValue = document.getElementById("checkbox").value;
    if(optValue === "I"){
      document.getElementById("checkbox").value = "O";
      document.getElementById("emailPref").value = "O";
      document.getElementById("checkbox").checked = false;
    } else {
      document.getElementById("checkbox").value = "I";
      document.getElementById("emailPref").value = "I";
      document.getElementById("checkbox").checked = true;
    }
  }

The visible label for toggling the style (using CSS only)

<input type="checkbox" id="checkbox" name="emailPerm" value="$EMAIL_PERMISSION_STATUS_$" onload="initValue();" onclick="changeValue()">
<label class="toggle" for="checkbox"></label>

And the hidden input, the one that passes data back to our email platform

<input type="hidden" id="emailPref" name="EMAIL_PERMISSION_STATUS_" value="$EMAIL_PERMISSION_STATUS_$">

Additional info

On loading with I value, it appears as this (which would be the "O" value):

enter image description here

On clicking, after this state, the value does set to "O" and the styling remains the same. On a second click, the value goes back to "I" and displays properly:

enter image description here

**I apologize in advance if this is an obvious mistake, since I typically cannot use JavaScript in HTML emails but since this is technically presented as a landing page, it works.

Thanks!