General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 15th, 2003, 06:24 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
POST/GET variables

I was wondering what the best way to deal with checkboxes was... I think i've figured out a way that works, but to be honest i'm not pleased. I'm hoping there was a better way.

The checkbox is a response to a yes/no question (hence Y/N).

Here's the code I've used:

PHP Code:
 $check1 = !empty($HTTP_POST_VARS['check1']) ? $HTTP_POST_VARS['check1'] : "";

if(
$check1=="checkbox") {
    
$check1 "Y";
} else {
    
$check1 "N";
}
echo 
$check1

Reply With Quote
  #2  
Old January 15th, 2003, 07:16 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Well, any way you feel is best and can understand better is always the best way. Me, I would do this in this particular scenerio ->
PHP Code:
/*************************************
Initialize Script Variables
*************************************/
$q_one = ( bool ) false;
$q_two = ( bool ) false;
$q_thr = ( bool ) false;
$q_fou = ( bool ) false;
$q_fiv = ( bool ) false;
$q_six = ( bool ) false;
$q_sev = ( bool ) false;
/*************************************
Check Incoming Answers
*************************************/
if ( !empty( $_POST['ques_one'] ) ) $q_one = ( bool ) true;
if ( !empty( 
$_POST['ques_two'] ) ) $q_two = ( bool ) true;
if ( !empty( 
$_POST['ques_thr'] ) ) $q_thr = ( bool ) true;
if ( !empty( 
$_POST['ques_fou'] ) ) $q_fou = ( bool ) true;
if ( !empty( 
$_POST['ques_fiv'] ) ) $q_fiv = ( bool ) true;
if ( !empty( 
$_POST['ques_six'] ) ) $q_six = ( bool ) true;
if ( !empty( 
$_POST['ques_sev'] ) ) $q_sev = ( bool ) true

Now, the above would obviously be for seven questions. On my form or the questionaire, my checkboxes would be set as '0' for no and '1' for yes.

empty() returns true or empty if the value is '( int ) 0' - so if the value of the $_POST['var'] comes in with an empty() value (or 0), the script would make no changes to the initialized variable as it is already set at '0', or false. If the value comes in as !empty() or '1', I set the variable to true. Now, after that the checking is trivial ->
PHP Code:
if ( $q_one ) {
echo( 
'You answered yes to Q1' );
} else {
echo( 
'You answered no to Q1' );

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old January 15th, 2003, 07:58 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
thanks, that's pretty much exactly what i was looking for =)

it also answers a couple more questions that i never asked

much appreciation, thanks!

Reply With Quote
  #4  
Old January 16th, 2003, 08:26 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
Use it as an array

<form>
<input type="checkbox" name="check[]" value="1">1
<input type="checkbox" name="check[]" value="2">2
<input type="checkbox" name="check[]" value="3">3
<input type="submit" name="submit">
</form>

the php code:

for($i = 0; $i < sizeof($check); $i++) {
print $check[$i];
}
__________________
Regards,
Ramiro Varandas Jr.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > POST/GET variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway