Welcome Guest, Not a member yet? Register   Sign In
Get value from checkboxes and userfile to update
#1

[eluser]Omaplie[/eluser]
Hi folks,

The user filled in a form with checkboxes.
When he want to modify this form, how to do to
have a list of checkboxes already checked ?

And the same for the image, how to do to display
the image that he has already sent, with the good path ?

Thank you very much.
#2

[eluser]vitoco[/eluser]
"When he want to modify this form" did you mean, when you reload the data (previously submitted ) in the same form ?, if that's correct , yo can use the "checked" atribute for checkboxes. About the input file, what did you mean with "the good path" ?

saludos
#3

[eluser]PhilTem[/eluser]
I'd say: It's all about the storage of data.

And, furthermore: Also about learning how to store data either in flat file format or a database.
#4

[eluser]Omaplie[/eluser]
Hi,

Thank you for your answer.
I mean when the user want to edit a post, I would like that the checkboxes
checked before be checked.

For the storage, I store checked input in only one column.
Code:
<?php
            $totoche = $this->input->post('totoche'); // GET VALUES CHECKED

            $t = implode(', ', $totoche); //CREATE AN ARRAY WITH ALL VALUES
?>

I think to try if it's already checked I need to use
Code:
<?php explode() ?>
but I don't really now how.

And for the image, I store the encrypted name of the image in the database.

Thank you a lot.
#5

[eluser]vitoco[/eluser]
it's easier to give you an approach if you post your form.
#6

[eluser]Omaplie[/eluser]
Ok, sorry :

Code:
<?php
<div class="admin_up">
<h3>Ajouter un totem</h3>
&lt;?php echo form_open_multipart('totem/add_totem', array('class' => 'toupdate additot')); ?&gt;

    <p>
        &lt;?php echo form_error('nom_totem', '<span class="error">', '</span>'); ?&gt;
        <label for="nom_totem">Totem</label>
        &lt;input type="text" id="nom_totem" name="nom_totem" /&gt;
    </p>
    
    <p>
        &lt;?php echo form_error('userfile', '<span class="error">', '</span>'); ?&gt;
        <label for="userfile">Image du totem</label>
        &lt;input type="file" id="userfile" name="userfile" /&gt;
        <span class="infoim">L’image doit être inférieure à 200ko (gif,jpg,jpeg,png)</span>
        <span class="infoim">La taille idéale est de 150px sur 150px</span>
    </p>
    
    <p>
        &lt;?php echo form_error('description_totem', '<span class="error">', '</span>'); ?&gt;
        <label for="description_totem">Description du totem</label>
        &lt;textarea name="description_totem" cols="40" rows="6" id="description_totem" &gt;&lt;/textarea>
    </p>
    
<table>
  
   <tr>
       <td>&lt;input type="checkbox" name="totoche[]" value="Rusé" id="ruse" /&gt;&lt;/td>
       <td><label for="ruse">Rusé</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Beau" id="beau" /&gt;&lt;/td>
       <td><label for="beau">Beau</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Fort" id="fort" /&gt;&lt;/td>
       <td><label for="fort">Fort</label></td>
   </tr>

  <tr>
       <td>&lt;input type="checkbox" name="totoche[]" value="Sociable" id="Sociable" /&gt;&lt;/td>
       <td><label for="Sociable">Sociable</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Débrouillard" id="Débrouillard" /&gt;&lt;/td>
       <td><label for="Débrouillard">Débrouillard</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Aquatique" id="Aquatique" /&gt;&lt;/td>
       <td><label for="Aquatique">Aquatique</label></td>
   </tr>

   <tr>
       <td>&lt;input type="checkbox" name="totoche[]" value="Meneur" id="Meneur" /&gt;&lt;/td>
       <td><label for="Meneur">Meneur</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Gourmand" id="Gourmand" /&gt;&lt;/td>
       <td><label for="Gourmand">Gourmand</label></td>
       <td>&lt;input type="checkbox" name="totoche[]" value="Paresseux" id="Paresseux" /&gt;&lt;/td>
       <td><label for="Paresseux">Paresseux</label></td>
   </tr>
</table>



    <p>
        &lt;input type="submit" value="Ajouter le totem" /&gt;
    </p>

&lt;?php echo form_close(); ?&gt;
</div>
<hr/>
?&gt;

Do you understand what I've done ?
#7

[eluser]Omaplie[/eluser]
I can get values checked before but I don't how to say that
if the value exist in the DB the checkbox must be checked.
#8

[eluser]vitoco[/eluser]
Like this
Code:
&lt;?
$Meneur_is_checked = true / false ; // FROM DB VALUE
?&gt;
<td>&lt;input type="checkbox" name="totoche[]" value="Meneur" id="Meneur" &lt;?=( $Meneur_is_checked  ? 'checked="checked"' : '' )?&gt;/&gt;&lt;/td>

Saludos
#9

[eluser]Omaplie[/eluser]
Hi,

Thank you for your help.
But how can you compare the value from the « value » from the checkbox
with value get from the database ?

I need to get the value from the checkbox to compare with the value from
the database but I don't know how to do.
#10

[eluser]vitoco[/eluser]
I'm not used to display checkboxes as array...but i've tested this in FF and it works

Code:
&lt;?
/*
    - Use explicit indexes in checboxes
    - in the db table,  make field names matching those index like 'chk_10 INT(1)' with values 1/0 , 0 as default.
    - get the values in an array to compare and set the checked attribute
*/
    $cheboxes = arra(
        'chk_10' => 1 ,
        'chk_20' => 0 ,
        'chk_30' => 1 ,
    );

?&gt;
<tr>
       <td>&lt;input type="checkbox" name="totoche[10]" value="Rusé" id="ruse" &lt;?=( $checkboxes['chk_10'] == 1 ? 'checked="checked"' : '' )?&gt;/&gt;&lt;/td>
       <td><label for="ruse">Rusé</label></td>
       <td>&lt;input type="checkbox" name="totoche[20]" value="Beau" id="beau"  &lt;?=( $checkboxes['chk_20'] == 1 ? 'checked="checked"' : '' )?&gt;/&gt;&lt;/td>
       <td><label for="beau">Beau</label></td>
       <td>&lt;input type="checkbox" name="totoche[30]" value="Fort" id="fort"  &lt;?=( $checkboxes['chk_30'] == 1 ? 'checked="checked"' : '' )?&gt;/&gt;&lt;/td>
       <td><label for="fort">Fort</label></td>
   </tr>

Saludos




Theme © iAndrew 2016 - Forum software by © MyBB