phpScheduleIt
June 20, 2013, 01:05:45 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: adding a persistent checkbox to profile screen  (Read 4534 times)
emonsta
Newbie
*

Karma: 0
Posts: 13


« on: May 03, 2006, 07:33:29 PM »

Ok, i know this is kindergarten php and i probably shouldn't be asking this here, but i'm wasting hours trying to figure it out, and i'm getting nowhere...
Im trying to add a single persistent checkbox field to the profile form that asks the user if they want to receive promotional material. I can get the checkbox to pass the value to the database, but i can't get it to read the value in the database and return it as a checked box. Have tried every instruction I can find and nothing's working, mainly because i have no idea what i'm doing. i suspect its really simple. I'm trying to edit the auth.template.php file. the following ocode snippet works to pass the value tot he database. i've tried various '_post' and 'is checked' type things to get it to display but no need to show all that. can you please tell me what I need to add to this and where to bring up the value stored in the database.

<td> <input type="checkbox" name="promo" value="<?php echo isset($data['promo']) && ($data['promo'] == 1) ? '' : 1 ?>"/></td>

many thanks, my hairdresser will thank you too if you can stop me from putting out my hair Smiley
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5506


WWW
« Reply #1 on: May 04, 2006, 10:03:21 AM »

Sure, this is probably 2 small issues.

1) You need to change some stuff in lib/User.class.php
Add
Code:
var $promo;
up under
Code:
var $is_admin;

load_by_id() needs to set the value of "promo" coming back from the database
get_user_data() needs to set the value of "promo" just like all the other variables in that function

2) Try using this HTML

Code:
<?php
$checked 
= isset&#40;$data['promo'&#93;&#41; && &#40;$data['promo'&#93; == 1&#41;;
?>

<input type="checkbox" name="promo" value="1" <?php $checked 'checked="checked"' &#58; '' ?> />



This will work because checkboxes and radio buttons don't even show up in the $_POST if they are not checked.  So you can always set the value, but only check the box if the data is set.

Now when it comes back, you should check isset($_POST['promo']) to see if the user checked it or not.
Logged
emonsta
Newbie
*

Karma: 0
Posts: 13


« Reply #2 on: May 05, 2006, 05:16:43 AM »

Nick, you ARE a wonder. you've just rescued me and all my loved ones from certain insanity  :wink:
thanks, its working.

just a note: being a bunny, i wasn't sure what you meant about
you should check isset($_POST['promo'])
so i experimented by sticking an echo statement in the following
<input type="checkbox" name="promo" value="1" <?php echo $checked ? 'checked="checked"' : '' ?> />
and that seems to have worked.
am v happy now    Cheesy
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5506


WWW
« Reply #3 on: May 05, 2006, 09:34:08 AM »

Glad to hear all is well
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!