Re: [PHP] making checkbox's and radio buttons sticky
Ted Passey wrote: thanks Jochem - I am learning alot about arrays. I think this may be what i am looking for if (in_array('September 9th', $gmev)) it seems to work great... is that $gmev being created automatically? if so you are using register_globals - which is one step in the direction of the dark side - for the love of insert preferred god/icon/hero/etc use the element in the $_POST superglobal array instead i.e. $_POST['gmev'] However...when you get one problem solved, another pops up... not problems - challenges. The checkboxes work as long as one is selected, but if the page is submitted without checking any boxes in the array.. you get the warning Warning: in_array(): Wrong datatype for second argument it wants an array - your not giving it an array. Any idea on how to resolve this? how do you think it should be resolved? what about checking the variable before blindly using it - time to find a way to check if a var is an array (or even exists in the scope of the current code) ... there is a function that does this - it's name is so selfevident that I'm not even going to name it - seek and you shall find. Thanks, Zedleon - Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Ted Passey [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] .php.net Sent: Saturday, August 13, 2005 4:40 PM Subject: Re: [PHP] making checkbox's and radio buttons sticky Ted Passey wrote: ok, thanks again Jochem! Its good to know their is support for php from good people like you. The radio's are working great! However i still have a small issue with the checkboxes.. They appeared to be working properly...but now all the checkboxes in the array are checking Not sure whats going on...I can tell you this however..my brain in mush. here is what i have... HTML is: input name=gmev[] type=checkbox id=gmev value=September 9thSeptember 9th input name=gmev[] type=checkbox id=gmev value=October 14thOctober 14th input name=gmev[] type=checkbox id=gmev value=November 11th November 11th input name=gmev[] type=checkbox id=gmev value=December 9th December 9th PHP looks like this: ? if ($_POST['gmev']) { $_POST['gmev'] will be an array - you have to loop it and determine which of the date values (from the checkboxes) it contains - for each date found you have to set the corresponding checkbox. its time to learn about associative arrays, using array indexes and foreach loops! $checked = ' checked=checked'; } else { $checked = ''; } echo 'input name=gmev[] type=checkbox id=gmev',$checked,'/'; ? any Idea's Thanks in advance zed - Original Message - From: Jochem Maas [EMAIL PROTECTED] To: Ted Passey [EMAIL PROTECTED]; [php] PHP General List php-general@lists.php.net Sent: Friday, August 12, 2005 1:09 PM Subject: Re: [PHP] making checkbox's and radio buttons sticky Ted Passey wrote: Jochem, Thanks for your help...I can see your a great PHP programmer. flattery gets you everywhere - even if it isn't true. I'm not that bad - but lets leave the 'great' for those that really are - you know people who develop/invent the actual language - people who write books about it, people like that :-) oh and as long as it's php related make sure to atleast cc the list. The dynamic checkbox code you sent worked great! I am however have a problem with a set of radio buttons... I am trying to appy the same principle here... The problem I am encountering is the $checked value in the echo string will always show the button checked So no matter what is selected, it comes back to checked Any suggestions? HTML is: input name=member type=radio value=Yes checked Member I assume that should be?: input name=member type=radio value=Yes checked=checked Member input name=member type=radio value=NoProspective Member PHP is: ? if ($member) { if $member containseither 'Yes' or 'No' then it will equate to boolean true - which is what you are in fact testing try something like: if ($member == 'Yes') { $checked = ' checked=checked'; } else { $checked = ''; } echo 'input name=member type=radio',$checked,'/'; ? Thanks for the help... zed - Original Message - From: Jochem Maas [EMAIL PROTECTED] Newsgroups: php.general To: zedleon [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, August 11, 2005 9:18 PM Subject: Re: [PHP] making checkbox's and radio buttons sticky zedleon wrote: I am new to php and am in need of some guidance I am building a sticky form and am having trouble bringing in the data sticky as in honey? fields for checkbox's and radio button's. Any help on how to do this would be appreciated HTML form sample input name=gmev[] type=checkbox id=gmev value=September 9th/th PHP input name=gmev[] type=checkbox id=gmev value=? echo $gmev_day ?/th am I on the right track here? maybe, partially - generally radio buttons and checkboxes have fixed values
Re: [PHP] making checkbox's and radio buttons sticky
Support wrote: okI got it!! not wanting to go down the path of the darkside...I inserted the superglobals.. if (isset($_POST['gmev']) in_array('September 9th', $_POST['gmev'])) so did I get it right? there are many roads to Rome. using isset() and in_array() is a very good start indeed! (you'd be surprised at how many people don't check vars at all) you might consider either casting $_POST['gmev'] as an array at some stage: $myArr = (array)$_POST['gmev'] or also using is_array() to check that $_POST['gmev'] is actually an array. another technique sometimes used is to suppress the error in cases when you need speed AND you know the error is of no consequence: if (@in_array('September 9th', @$_POST['gmev'])) { // bla } notice 2 @ signs. the first suppresses the warning about possible in correct 2nd param to in_array() the second will suppress the notice if $_POST['gmev'] is not set. be very wary of the @ sign - don't use it lightly, most always using isset() in combination with a is_*() function is much much better (and more correct. also check out the ctype functions: http://php.net/ctype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] making checkbox's and radio buttons sticky
[EMAIL PROTECTED] wrote: Sorry, I will be out of the office until Monday 15th August. phil is risking being out of the office permanently ;-) Kind regards, Phil Ewington. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] making checkbox's and radio buttons sticky
Ted Passey wrote: Jochem, Thanks for your help...I can see your a great PHP programmer. flattery gets you everywhere - even if it isn't true. I'm not that bad - but lets leave the 'great' for those that really are - you know people who develop/invent the actual language - people who write books about it, people like that :-) oh and as long as it's php related make sure to atleast cc the list. The dynamic checkbox code you sent worked great! I am however have a problem with a set of radio buttons... I am trying to appy the same principle here... The problem I am encountering is the $checked value in the echo string will always show the button checked So no matter what is selected, it comes back to checked Any suggestions? HTML is: input name=member type=radio value=Yes checked Member I assume that should be?: input name=member type=radio value=Yes checked=checked Member input name=member type=radio value=NoProspective Member PHP is: ? if ($member) { if $member containseither 'Yes' or 'No' then it will equate to boolean true - which is what you are in fact testing try something like: if ($member == 'Yes') { $checked = ' checked=checked'; } else { $checked = ''; } echo 'input name=member type=radio',$checked,'/'; ? Thanks for the help... zed - Original Message - From: Jochem Maas [EMAIL PROTECTED] Newsgroups: php.general To: zedleon [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Thursday, August 11, 2005 9:18 PM Subject: Re: [PHP] making checkbox's and radio buttons sticky zedleon wrote: I am new to php and am in need of some guidance I am building a sticky form and am having trouble bringing in the data sticky as in honey? fields for checkbox's and radio button's. Any help on how to do this would be appreciated HTML form sample input name=gmev[] type=checkbox id=gmev value=September 9th/th PHP input name=gmev[] type=checkbox id=gmev value=? echo $gmev_day ?/th am I on the right track here? maybe, partially - generally radio buttons and checkboxes have fixed values - it's the 'are they selected' part that probably want to make dynamic... basically you need to conditionally add the attribute 'checked' (i.e. checked=checked) to the radios and checkboxes you want selected when the form is first shown. e.g. ? if ($thisChkBoxIsInitiallySelected) { $checked = ' checked=checked'; } else { $checked = ''; } echo 'input name=gmev[] type=checkbox id=gmev',$checked,'/'; ? of course there are a million different ways to write this kind of thing (i.e. don't take my example verbatim perse) but hopefully you get the idea. zed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] making checkbox's and radio buttons sticky
I am new to php and am in need of some guidance I am building a sticky form and am having trouble bringing in the data fields for checkbox's and radio button's. Any help on how to do this would be appreciated HTML form sample input name=gmev[] type=checkbox id=gmev value=September 9th/th PHP input name=gmev[] type=checkbox id=gmev value=? echo $gmev_day ?/th am I on the right track here? zed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] making checkbox's and radio buttons sticky
zedleon wrote: I am new to php and am in need of some guidance I am building a sticky form and am having trouble bringing in the data sticky as in honey? fields for checkbox's and radio button's. Any help on how to do this would be appreciated HTML form sample input name=gmev[] type=checkbox id=gmev value=September 9th/th PHP input name=gmev[] type=checkbox id=gmev value=? echo $gmev_day ?/th am I on the right track here? maybe, partially - generally radio buttons and checkboxes have fixed values - it's the 'are they selected' part that probably want to make dynamic... basically you need to conditionally add the attribute 'checked' (i.e. checked=checked) to the radios and checkboxes you want selected when the form is first shown. e.g. ? if ($thisChkBoxIsInitiallySelected) { $checked = ' checked=checked'; } else { $checked = ''; } echo 'input name=gmev[] type=checkbox id=gmev',$checked,'/'; ? of course there are a million different ways to write this kind of thing (i.e. don't take my example verbatim perse) but hopefully you get the idea. zed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php