Jump to content

Recommended Posts

Hello....

 

I'll try to explain this in a easy way.

 

Take a look at this link. This is the page to create a group.

Log in on the left side using username "test" and password "test"

http://www.fesan.cc/utvikling/dlight/index.php?page=create_group

 

In the action script the check box values are imploded and added to a database.

 

On another page i  want to edit the info in a selected group.

So I want to have the exact same output on the page but the values that earlier was created when making the group is supposed to be filled out.

 

You can try out this page and see that the "Gruppe Navn:" and "Gruppe Beskrivelse:" filled out with the values in the group.

 

http://www.fesan.cc/utvikling/dlight/index.php?page=change_group&id=5&gruppe=Ny_test

 

Now the thing a want to achieve is to make the check boxes an the right side to be checked if they are selected when creating the group.

 

Can i do this without making a HUGE if elseif statement using the explode?

I also expect the number of checkboxes will extend with time...

 

PS: Sorry but the page is in Norwegian!

 

Thanks in advance for any replies!

Link to comment
https://forums.phpfreaks.com/topic/150878-explode/
Share on other sites

Looks like you have other problems on your website as well (see attached screenshot). I suppose you're getting the text from a database and using a wrong collation. You need to use the same character set throughout your entire application, that's to say you need to save your files in that charset, you need to tell the client which charset it is and your database has to be in that charset.

 

Anyway, that's not relevant to your problem in this topic. Just thought I'd point it out.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/150878-explode/#findComment-792611
Share on other sites

i usually do:

 

<?php
  $options = array(
    1 => 'First Checkbox',
    2 => 'Second Checkbox',
    3 => 'Third Checkbox',
    4 => 'Fourth Checkbox',
    5 => 'Fifth Checkbox',
    6 => 'Sixth Checkbox',
  );
  $value = "1,4,5,6"; //This is the value from your DB
  $choices = explode(',',$value);//Now we have an array
  foreach($options as $k => $v){
    print '<input type="checkbox" name="foobar[]" value="'.htmlspecialchars($k).'" ';
    if(in_array($k,$choices))
      print 'CHECKED';
    print '/>'.htmlspecialchars($v).';
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/150878-explode/#findComment-792621
Share on other sites

  • 2 weeks later...

Hello....

 

Busy times and haven't had a Chance too look at it before now.

Had to modify the script a bit to get it to work... it looked like this in the end:

<?php
$options = array(
1 => $row['0'],
);
$value = $row['list_include'];
$choices = explode(',',$value);
foreach($options as $k => $v){
print '<label><input type="checkbox" name="foobar[]" value="'.htmlspecialchars($v).'" ';
if(in_array($v,$choices))
  print 'checked="checked"';
          print '/>'. htmlspecialchars($v). '</label><br>';
} 
?>

 

Thanks again for the help...

 

Just wonder about one thing. This is not the right place too ask but i hope for an answer anyway.

If a field in a form is disabled like this:

<input type='checkbox' name='checkbox[]' value='id' id='id' checked='checked' disabled='disabled'>

Does the value still post trough to the action script?

 

Link to comment
https://forums.phpfreaks.com/topic/150878-explode/#findComment-802633
Share on other sites

Just wonder about one thing. This is not the right place too ask but i hope for an answer anyway.

If a field in a form is disabled like this:

<input type='checkbox' name='checkbox[]' value='id' id='id' checked='checked' disabled='disabled'>

Does the value still post trough to the action script?

 

i don't believe so

Link to comment
https://forums.phpfreaks.com/topic/150878-explode/#findComment-802644
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.