Jump to content

Newbie - Checkbox Without Array


j.g.

Recommended Posts

Hi All!

 

I have a question regarding implementing a checkbox that DOESN'T use arrays -- everything i find when i google has arrays in it!  So, I'm hoping someone here can help me come up with a solution to my problem.

 

I have a checkbox that a user can check (default will be to have it NOT checked) - and once it's checked, to keep it checked until the user unselects it again.

 

Here's my checkbox code:

<input type ="submit" name="cv_permission" type="checkbox">

 

What do I have to do to keep it turned 'ON' once it's checked?

 

Thanks for your time and help!

-j.g.

Link to comment
https://forums.phpfreaks.com/topic/62095-newbie-checkbox-without-array/
Share on other sites

Hi - Thanks for the replies....I think.  :-\

 

There's nothing wrong with arrays, I was just saying 'Without Array' since I'm only using one checkbox -> so I didn't think that an array was neccessary. But, if it is, then by all means, I can implement it with an array!

 

As I said, I'm a Newbie to PHP, so I apologize if my question is a bit on the novice side; that's why I come to this board ... to solve problems and learn new things along the way.  I'm sorry if my 'elementary question' offended anybody.

 

frost110 mentioned using sessions... I can look into how to do this; and if anyone else has any other helpful suggestions or ideas to share and aid in my solution, I'm open to hearing them!

 

Thanks!

-j.g.

implement an array with one element for christ's sakes.

 

anyway, when you want to get it to save, you are going to have to tell php to dynamically mark the checkbox as checked somehow.  by somehow, i mean with a database or sessions or something.  if it is a user preference, when the checkbox is posted store that the checkbox is true to the database.

 

when drawing the checkbox, you can do something like this, assuming the user property is "cv_permission"...

 

<input type="checkbox" name="cv_permission" <?php ($row['cv_permission']==true) ? echo "checked" : echo ""; ?> />

 

 

btw... in your original code you declared your checkbox as both a checkbox and a submit... not a good idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.