mardi 3 mai 2016

Persisting checkboxes php

I'm still fairly green with PHP and I'm trying to allow persisting data for my checkboxes and radios. I have attempted to try and do this myself, but I feel I may be missing somthing. I have tried to implement a similar solution I found here but to no avail.

Edit: What I'm asking is; is there a better way to capture persisting data for checkboxes, if so how would I go about it using chk[].

Here's what I have;

PHP / HTML - (located in index.php)

<input type="checkbox" id="chk-1" class="ca" name="chk[]" value="JETvarnish 3D Evo" 
<?php if (in_array('JETVarnish 3D Evo', $chk)) ? 'checked' : ''; ?>
/>
<label for="chk-1">JETvarnish 3D Evo</label>
<br/>

PHP - (located in frmPost.php)

// set post data as array.
  $_SESSION['post-data'] = $_POST;

// checkbox as array.
  $selectedProjects  = 'None';
  if(isset($_POST['chk']) && is_array($_POST['chk']) && count($_POST['chk']) > 0){
      $selectedProjects = implode(', ', $_POST['chk']);
  }

Any assistance I could get with this would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire