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
Share on other sites

Currently, when I leave the page that the checkbox is on and then come back to it, the checkbox is gone...  it's not saving it, it's clearing it out everytime....

 

Hope that helps!

-j.g.

 

Well yea.

 

You need to use sessions.

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
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.