Re: [PHP] Checkbox in PHP form
INPUT class=text id=myCheck1 type=checkbox?php echo( $row[33] == 'no' ? ' checked=checked' : '' ); ? value=PFDs name=f_sequipment1/bfont size=2PFDsb Or with short tags: INPUT class=text id=myCheck1 type=checkbox?= $row[33] == 'no' ? ' checked=checked' : '' ? value=PFDs name=f_sequipment1/bfont size=2PFDsb Adam. On Sun, Nov 8, 2009 at 5:39 PM, Ernie Kemp ernie.k...@sympatico.ca wrote: Need some help here with checkboxes in an html form. My issue is I have a form that needs to be viewed with checkboxes filled in depending on the values in the table. I tried: INPUT class=text id=myCheck1 type=checkbox ?php if ( $row[33] = 'no') { echo checked=yes; } else { echo ''; } ? value=PFDs name=f_sequipment1/bfont size=2PFDsb but the checkbox field is always checked. I thought of JavaScript also but it would have to be a “if $row[33] then run a JavaScript function” . This is not working for me neither. Sorry if this seems trivial but I need your help. Thanks in advance. -- Adam Randall http://www.xaren.net AIM: blitz574
[PHP] Checkbox in PHP form
Need some help here with checkboxes in an html form. My issue is I have a form that needs to be viewed with checkboxes filled in depending on the values in the table. I tried: INPUT class=text id=myCheck1 type=checkbox ?php if ( $row[33] = 'no') { echo checked=yes; } else { echo ''; } ? value=PFDs name=f_sequipment1/bfont size=2PFDsb but the checkbox field is always checked. I thought of JavaScript also but it would have to be a if $row[33] then run a JavaScript function . This is not working for me neither. Sorry if this seems trivial but I need your help. Thanks in advance.
[PHP] checkbox unchecked
I have now tried to add many of the security hints on a web page and come to a problem. I am checking if the allowed fields match the sent fields. From the database I get the information if a checkbox is checked or not: ?php if($DB_a ==y) { $checked=checked; } else { $checked=; } ? input type=checkbox name=R_a value=y ?php echo $checked ? If the user takes out the checkmark the value will become and the field will not submitted which results in a missing field. $allowed = array(); $allowed[]='form'; $allowed[]='R_a'; $allowed[]='R_b'; $sent = $array_keys($_POST); if($allowed == $sent) { ... do some checking ... } else { echo Expected input fields do not match!; } break; How can I force a n for not checked in the input field? or how can I solve that? bye Ronald -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
Ronald Wiplinger wrote: How can I force a n for not checked in the input field? or how can I solve that? Either use radio buttons or a drop down for the input field. Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
Stephen wrote: Ronald Wiplinger wrote: How can I force a n for not checked in the input field? or how can I solve that? Either use radio buttons or a drop down for the input field. Thanks! Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
First of all, using y and n for boolean values (such as a checkbox) is very sloppy. n is boolean True. A boolean value should evaluate correctly in a boolean context. For that, you should use 1 and 0 for your values. What I usually do is this: input type=hidden name=foo value=0 / input type=checkbox name=foo value=1 ?php echo $checked; ? / Then when it gets submitted, foo will get the value of the form element that was submitted last that has a value. That is, if the checkbox is checked then foo will be 1, otherwise it will be 0. That gives you a nice, clean boolean value you can rely on being present (mostly g). On Sunday 02 December 2007, Ronald Wiplinger wrote: I have now tried to add many of the security hints on a web page and come to a problem. I am checking if the allowed fields match the sent fields. From the database I get the information if a checkbox is checked or not: ?php if($DB_a ==y) { $checked=checked; } else { $checked=; } ? input type=checkbox name=R_a value=y ?php echo $checked ? If the user takes out the checkmark the value will become and the field will not submitted which results in a missing field. $allowed = array(); $allowed[]='form'; $allowed[]='R_a'; $allowed[]='R_b'; $sent = $array_keys($_POST); if($allowed == $sent) { ... do some checking ... } else { echo Expected input fields do not match!; } break; How can I force a n for not checked in the input field? or how can I solve that? bye Ronald -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
I did once, if I remember once, this strategy: input type=hidden name=R_a value=n input type=checkbox name=R_a value=y ?php echo $checked ? If checked, you will have value y. Though, if unchecked, or it was checked and visitor unchecked, the value should be n. ;) -afan Ronald Wiplinger wrote: I have now tried to add many of the security hints on a web page and come to a problem. I am checking if the allowed fields match the sent fields. From the database I get the information if a checkbox is checked or not: ?php if($DB_a ==y) { $checked=checked; } else { $checked=; } ? input type=checkbox name=R_a value=y ?php echo $checked ? If the user takes out the checkmark the value will become and the field will not submitted which results in a missing field. $allowed = array(); $allowed[]='form'; $allowed[]='R_a'; $allowed[]='R_b'; $sent = $array_keys($_POST); if($allowed == $sent) { ... do some checking ... } else { echo Expected input fields do not match!; } break; How can I force a n for not checked in the input field? or how can I solve that? bye Ronald -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
Just to add my two cents - I don't think it matters much what tokens you use to represent true or false, since you're going to be explicitly checking them on the server end anyway. I can't see much difference in principle between, for example: if ($_GET['foo'] == 'y')... and if ($_GET['foo'] == '1')... or even if ($_GET['foo'] == 'Oui')... One should really not do be doing just if ($_GET['foo']) anyway. Checking that a specific value is passed, rather than just some value that PHP evaluates to true or false, is one way to catch possible form hacking. For general reference, there are a number of php security howtos out there on how to sanitize user input, but I'll leave finding them as an 'excercize for the reader' at the moment. I suppose using 0/1 does have the advantage of 'doing the right thing' if a if ($_GET['foo']) creeps into your code, though. As would using 'Y'/''. That being said, I've used 0/1 along with y/n in the past; it depends on whether I'm thinking like a programmer or a human ;) steve At 12:36 PM -0600 12/2/07, Larry Garfield wrote: First of all, using y and n for boolean values (such as a checkbox) is very sloppy. n is boolean True. A boolean value should evaluate correctly in a boolean context. For that, you should use 1 and 0 for your values. What I usually do is this: input type=hidden name=foo value=0 / input type=checkbox name=foo value=1 ?php echo $checked; ? / Then when it gets submitted, foo will get the value of the form element that was submitted last that has a value. That is, if the checkbox is checked then foo will be 1, otherwise it will be 0. That gives you a nice, clean boolean value you can rely on being present (mostly g). On Sunday 02 December 2007, Ronald Wiplinger wrote: I have now tried to add many of the security hints on a web page and come to a problem. I am checking if the allowed fields match the sent fields. From the database I get the information if a checkbox is checked or not: ?php if($DB_a ==y) { $checked=checked; } else { $checked=; } ? input type=checkbox name=R_a value=y ?php echo $checked ? If the user takes out the checkmark the value will become and the field will not submitted which results in a missing field. $allowed = array(); $allowed[]='form'; $allowed[]='R_a'; $allowed[]='R_b'; $sent = $array_keys($_POST); if($allowed == $sent) { ... do some checking ... } else { echo Expected input fields do not match!; } break; How can I force a n for not checked in the input field? or how can I solve that? bye Ronald -- +--- my people are the people of the dessert, ---+ | Steve Edberghttp://pgfsun.ucdavis.edu/ | | UC Davis Genome Center[EMAIL PROTECTED] | | Bioinformatics programming/database/sysadmin (530)754-9127 | + said t e lawrence, picking up his fork + -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
nice! but to avoid confusion it should read (assuming that $checked is a boolean variable): input type=hidden name=foo value=0/ input type=checkbox name=foo value=1?php if($checked) echo ' checked'; ?/ IMHO Larry Garfield wrote: First of all, using y and n for boolean values (such as a checkbox) is very sloppy. n is boolean True. A boolean value should evaluate correctly in a boolean context. For that, you should use 1 and 0 for your values. What I usually do is this: input type=hidden name=foo value=0 / input type=checkbox name=foo value=1 ?php echo $checked; ? / Then when it gets submitted, foo will get the value of the form element that was submitted last that has a value. That is, if the checkbox is checked then foo will be 1, otherwise it will be 0. That gives you a nice, clean boolean value you can rely on being present (mostly g). On Sunday 02 December 2007, Ronald Wiplinger wrote: I have now tried to add many of the security hints on a web page and come to a problem. I am checking if the allowed fields match the sent fields. From the database I get the information if a checkbox is checked or not: ?php if($DB_a ==y) { $checked=checked; } else { $checked=; } ? input type=checkbox name=R_a value=y ?php echo $checked ? If the user takes out the checkmark the value will become and the field will not submitted which results in a missing field. $allowed = array(); $allowed[]='form'; $allowed[]='R_a'; $allowed[]='R_b'; $sent = $array_keys($_POST); if($allowed == $sent) { ... do some checking ... } else { echo Expected input fields do not match!; } break; How can I force a n for not checked in the input field? or how can I solve that? bye Ronald -- Larry GarfieldAIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- View this message in context: http://www.nabble.com/checkbox-unchecked-tf4932527.html#a14119395 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
At 12:36 PM -0600 12/2/07, Larry Garfield wrote: First of all, using y and n for boolean values (such as a checkbox) is very sloppy. n is boolean True. A boolean value should evaluate correctly in a boolean context. For that, you should use 1 and 0 for your values. What I usually do is this: input type=hidden name=foo value=0 / input type=checkbox name=foo value=1 ?php echo $checked; ? / Then when it gets submitted, foo will get the value of the form element that was submitted last that has a value. That is, if the checkbox is checked then foo will be 1, otherwise it will be 0. That gives you a nice, clean boolean value you can rely on being present (mostly g). Larry: Not that you said otherwise, but if the programmer does not set the value for a checkbox, html will provide values -- that may lead to confusion for newer programmers. See here: http://webbytedd.com//checkbox/ If you will note, without specifically setting the value, html will return on. Also, I'm sure it's an oversight, but your code above should be: ?php if ($foo) echo('checked'); ? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
On Dec 2, 2007 1:08 PM, tedd [EMAIL PROTECTED] wrote: At 12:36 PM -0600 12/2/07, Larry Garfield wrote: First of all, using y and n for boolean values (such as a checkbox) is very sloppy. n is boolean True. A boolean value should evaluate correctly in a boolean context. For that, you should use 1 and 0 for your values. What I usually do is this: input type=hidden name=foo value=0 / input type=checkbox name=foo value=1 ?php echo $checked; ? / Then when it gets submitted, foo will get the value of the form element that was submitted last that has a value. That is, if the checkbox is checked then foo will be 1, otherwise it will be 0. That gives you a nice, clean boolean value you can rely on being present (mostly g). Larry: Not that you said otherwise, but if the programmer does not set the value for a checkbox, html will provide values -- that may lead to confusion for newer programmers. See here: http://webbytedd.com//checkbox/ If you will note, without specifically setting the value, html will return on. Also, I'm sure it's an oversight, but your code above should be: ?php if ($foo) echo('checked'); ? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php You don't need to do anything. input type=checkbox name=likes_pie / When it's submitted: ?php if ($_GET['likes_pie']) // checked else // not -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox unchecked
At 1:23 PM -0800 12/2/07, Casey wrote: On Dec 2, 2007 1:08 PM, tedd [EMAIL PROTECTED] wrote: You don't need to do anything. input type=checkbox name=likes_pie / When it's submitted: ?php if ($_GET['likes_pie']) // checked else // not That's true unless you're pulling data in from somewhere else (i.e., a dB). Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox Hidden Field to Delete Row
Ave, I¹m stuck on a problem here. I have a file manager kind of application and I¹m trying to add the functionality to delete multiple files. Basically, there¹s a bunch of rows generated dynamically. Each row has a checkbox for ³Delete² option, and a hidden field which contains the name of the File associated with the record. If a user checks a checkbox to delete certain rows, it should be able to delete those rows from mySQL as well as delete the files associated with that record. I created both the checkboxes the hidden fields to be Arrays. I run a loop to delete all rows (based on ID¹s) where the checkbox was Checked. It does that part fine... The problem is linking the Filename array to the Checkbox Array. It deletes the first two files uploaded no matter what rows are checked. Basically, the Filename array is not associating with the Checkbox array. So if a person checks the 3rd and 5th checkbox... The 3rd 5th row is deleted from mySQL, but the 1st and 2nd file is deleted, not the 3rd 5th. Following is my code to generate the checkboxes hidden fields... td width=15span class=\style11\ input type=checkbox name=thisID[] value=$myrow[ID]input type=hidden name=\PF[]\ value=\imsafm/$showfilesuser/$myrow[filename]\input type=hidden name=login value=$loginINPUT TYPE=hidden name=showfilesuser value=$showfilesuser/td Following is the code to delete the checked rows/files... for($I=0;$Isizeof($thisID);$I++) { $sql = DELETE FROM file WHERE ID='$thisID[$i]'; $result = mysql_query($sql) or die(Fatal Error: .mysql_error()); $thefile = $PF[$i]; unlink($thefile); } I have no clue what to do... It¹s just not working out. Rahul S. Johari Coordinator, Internet Administration Informed Marketing Services Inc. 500 Federal Street, Suite 201 Troy NY 12180 Tel: (518) 687-6700 x154 Fax: (518) 687-6799 Email: [EMAIL PROTECTED] http://www.informed-sources.com
Re: [PHP] Checkbox Hidden Field to Delete Row
On Thursday 01 June 2006 12:58, Rahul S. Johari wrote: Ave, I¹m stuck on a problem here. I have a file manager kind of application and I¹m trying to add the functionality to delete multiple files. Basically, there¹s a bunch of rows generated dynamically. Each row has a checkbox for ³Delete² option, and a hidden field which contains the name of the File associated with the record. If a user checks a checkbox to delete certain rows, it should be able to delete those rows from mySQL as well as delete the files associated with that record. I created both the checkboxes the hidden fields to be Arrays. I run a loop to delete all rows (based on ID¹s) where the checkbox was Checked. It does that part fine... The problem is linking the Filename array to the Checkbox Array. It deletes the first two files uploaded no matter what rows are checked. Basically, the Filename array is not associating with the Checkbox array. So if a person checks the 3rd and 5th checkbox... The 3rd 5th row is deleted from mySQL, but the 1st and 2nd file is deleted, not the 3rd 5th. Rahul S. Johari The problem is coming from how checkboxes submit their information to the form. Only the checked checkboxes will actually send data. The unchecked ones will not send anything. Hidden fields differ, in that they ALWAYS send their data. This is probably causing a mis-match between the two arrays. You could verify that by doing a var_dump on the arrays before you delete anything. I would suggest that since you keep a record of the file in the database, include the file location in that database record. Then before you delete it, get the file name, delete the file, then delete the record. I think that would save you a bunch of headaches. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Hidden Field to Delete Row - SOLVED
Ave, I spent 3 hours trying to find or develop a solution for this problem... And believe it or not, within 3 minutes of sending the problem to the mailing list, I actually generated a solution!! Ray, you’re spot on with what’s actually happening, but this is what I did to resolve it... Here’s my code to generate the Dynamic Row with Checkboxes: td width=15span class=\style11\ input type=checkbox name=thisID[] value=\$myrow[ID]#imsafm/$showfilesuser/$myrow[filename]\input type=hidden name=login value=$loginINPUT TYPE=hidden name=showfilesuser value=$showfilesuser/td I completely eliminated the Hidden field... Instead, added the value of both the Row ID the Filename to the checkbox, with a seperator “#”. Here’s my code to delete the Row Corresponding File: foreach($thisID AS $value) { $pieces = explode(#, $value); $sql = DELETE FROM file WHERE ID='$pieces[0]'; $result = mysql_query($sql) or die(Fatal Error: .mysql_error()); $thefile = $pieces[1]; unlink($thefile); } As you can see, I basically explode the Array on the “#” seperator, and delete the Row File. Is working like a charm!! On 6/1/06 4:07 PM, Ray Hauge [EMAIL PROTECTED] wrote: On Thursday 01 June 2006 12:58, Rahul S. Johari wrote: Ave, I¹m stuck on a problem here. I have a file manager kind of application and I¹m trying to add the functionality to delete multiple files. Basically, there¹s a bunch of rows generated dynamically. Each row has a checkbox for ³Delete² option, and a hidden field which contains the name of the File associated with the record. If a user checks a checkbox to delete certain rows, it should be able to delete those rows from mySQL as well as delete the files associated with that record. I created both the checkboxes the hidden fields to be Arrays. I run a loop to delete all rows (based on ID¹s) where the checkbox was Checked. It does that part fine... The problem is linking the Filename array to the Checkbox Array. It deletes the first two files uploaded no matter what rows are checked. Basically, the Filename array is not associating with the Checkbox array. So if a person checks the 3rd and 5th checkbox... The 3rd 5th row is deleted from mySQL, but the 1st and 2nd file is deleted, not the 3rd 5th. Rahul S. Johari The problem is coming from how checkboxes submit their information to the form. Only the checked checkboxes will actually send data. The unchecked ones will not send anything. Hidden fields differ, in that they ALWAYS send their data. This is probably causing a mis-match between the two arrays. You could verify that by doing a var_dump on the arrays before you delete anything. I would suggest that since you keep a record of the file in the database, include the file location in that database record. Then before you delete it, get the file name, delete the file, then delete the record. I think that would save you a bunch of headaches. Rahul S. Johari Coordinator, Internet Administration Informed Marketing Services Inc. 500 Federal Street, Suite 201 Troy NY 12180 Tel: (518) 687-6700 x154 Fax: (518) 687-6799 Email: [EMAIL PROTECTED] http://www.informed-sources.com
Re: [PHP] Checkbox Hidden Field to Delete Row - SOLVED
On Thursday 01 June 2006 13:15, Rahul S. Johari wrote: Ave, I spent 3 hours trying to find or develop a solution for this problem... And believe it or not, within 3 minutes of sending the problem to the mailing list, I actually generated a solution!! Ray, you’re spot on with what’s actually happening, but this is what I did to resolve it... Here’s my code to generate the Dynamic Row with Checkboxes: td width=15span class=\style11\ input type=checkbox name=thisID[] value=\$myrow[ID]#imsafm/$showfilesuser/$myrow[filename]\input type=hidden name=login value=$loginINPUT TYPE=hidden name=showfilesuser value=$showfilesuser/td I completely eliminated the Hidden field... Instead, added the value of both the Row ID the Filename to the checkbox, with a seperator “#”. Here’s my code to delete the Row Corresponding File: foreach($thisID AS $value) { $pieces = explode(#, $value); $sql = DELETE FROM file WHERE ID='$pieces[0]'; $result = mysql_query($sql) or die(Fatal Error: .mysql_error()); $thefile = $pieces[1]; unlink($thefile); } As you can see, I basically explode the Array on the “#” seperator, and delete the Row File. Is working like a charm!! Tad different, but that will definitely work as well. It's a long shot, but just make sure that filenames don't have a # in them. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Hidden Field to Delete Row - SOLVED
Ray, Interestingly, I don't' allow special characters in File Names for files being uploaded to the File Manager. So that problem won't occur. Thanks. On 6/1/06 4:23 PM, Ray Hauge [EMAIL PROTECTED] wrote: On Thursday 01 June 2006 13:15, Rahul S. Johari wrote: Tad different, but that will definitely work as well. It's a long shot, but just make sure that filenames don't have a # in them. Rahul S. Johari Coordinator, Internet Administration Informed Marketing Services Inc. 500 Federal Street, Suite 201 Troy NY 12180 Tel: (518) 687-6700 x154 Fax: (518) 687-6799 Email: [EMAIL PROTECTED] http://www.informed-sources.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox value
Hello, I have a checkbox in a form. How can I determine if the user has set the checkbox on or not? Thanks -Will -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox value
isset($_POST['checkboxname']) or isset($_GET['checkboxname']) depending on the method of your form. a good thing to do is to do var_dump($_POST) or var_dump($_GET) to see all the values posted from the form... hth ken On Thu, 24 Mar 2005 15:42:10 +0200, William Stokes [EMAIL PROTECTED] wrote: Hello, I have a checkbox in a form. How can I determine if the user has set the checkbox on or not? Thanks -Will -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox value
# index.php form method=post action=index.php ?php $checked = ($_POST['CheckThis'] == 'Yes') ? 'checked' : '' ; input type=checkbox name=CheckThis value=Yes ?= $checked ? input type=Submit value=Submit /form -afan William Stokes wrote: Hello, I have a checkbox in a form. How can I determine if the user has set the checkbox on or not? Thanks -Will -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox arrays and validation
Hi all, this might be slightly off-topic in a way but Im looking for help not flaming. Ok I have a checkbox array that I populate from a DB using php: while ($row = mysql_fetch_array($result)) echo(input type=checkbox name=chkmodels[] value= . $row['models_id'] . . $row['models_type'] . br); So when I want to see each variable in the array I use: foreach ($_POST['chkmodels'] as $c) { echo(br value: . $c); } this is fine. but what I want to clarify is that if I change my PHP echo statement to: echo(input type=checkbox name=chkmodels value= . $row['models_id'] . . $row['models_type'] . br); basically without the [] then it is still recognised as an array. But when the array is passed back it is returned as a string separated by commas. Then I should use the split() function to create an array. IE: $modelsArray = split('[,]', $chkmodels); however when I try the second way (without the []) like this: if(isset($_POST['chkmodels'])) $selModels=$_POST['chkmodels']; else header(Location: ../freesample.php); if(isset($selModels)) { echo(selmodels: .$selModels); $selModelsInd = split('[,]',$selModels); echo(brInd modesl . $selModelsInd); foreach ($selModelsInd as $c) { echo(br value: . $c); } } I get the following results, when I select 2 checkboxes: selmodels: 2 Ind modeslArray value: 2 this is wrong and should output the following: selmodels: 2 Ind modeslArray value: 1 value: 2 as the values of the selected checkboxes are 1 and 2 and also there are two that are selected. Here is the OT part. how do I reference the checkboxes in javascript if the chkmodels[] is used? I have tried many things like: myCheckboxArray = document.forms[0].elements[chkmodels[]]; and myCheckboxArray = document.frmft[0].elements[chkmodels[]]; //where frmft is the name of my form. If someone could please advise me as to what I'm doing wrong or why the information is not being outputted as expected, that would be really helpful. thanks in advance Angelo Disclaimer This e-mail transmission contains confidential information, which is the property of the sender. The information in this e-mail or attachments thereto is intended for the attention and use only of the addressee. Should you have received this e-mail in error, please delete and destroy it and any attachments thereto immediately. Under no circumstances will the Cape Technikon or the sender of this e-mail be liable to any party for any direct, indirect, special or other consequential damages for any use of this e-mail. For the detailed e-mail disclaimer please refer to http://www.ctech.ac.za/polic or call +27 (0)21 460 3911 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox arrays and validation
On 05 October 2004 11:10, Angelo Zanetti wrote: Hi all, this might be slightly off-topic in a way but Im looking for help not flaming. Ok I have a checkbox array that I populate from a DB using php: while ($row = mysql_fetch_array($result)) echo(input type=checkbox name=chkmodels[] value= . $row['models_id'] . . $row['models_type'] . br); So when I want to see each variable in the array I use: foreach ($_POST['chkmodels'] as $c) { echo(br value: . $c); } this is fine. but what I want to clarify is that if I change my PHP echo statement to: echo(input type=checkbox name=chkmodels value= . $row['models_id'] . . $row['models_type'] . br); basically without the [] then it is still recognised as an array. But when the array is passed back it is returned as a string separated by commas. No, this is incorrect. You will see only the last value selected, returned as a simple scalar. PHP doesn't do automatic array-ification of multiple values -- that's why you need the [] in the name attribute. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox arrays and validation
Angelo Zanetti wrote: but what I want to clarify is that if I change my PHP echo statement to: echo(input type=checkbox name=chkmodels value= . $row['models_id'] . . $row['models_type'] . br); basically without the [] then it is still recognised as an array. But when the array is passed back it is returned as a string separated by commas. Then I should use the split() function to create an array. If you leave off the [], then only the last checkbox value remains in $_POST['chkmodels']. It is not passed as a comma separated string. If you look at the query string, you'll see something like this: ?chkmodels=1chkmodels=2 which means PHP makes $_POST['chkmodels'] equal to 1 for the first variable, then sets the same $_POST['chkmodels'] equal to 2 for the second variable in the query string. End result is one value (not an array) remaining in $_POST['chkmodels']. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox arrays and validation
Angelo Zanetti wrote: Here is the OT part. how do I reference the checkboxes in javascript if the chkmodels[] is used? I have tried many things like: myCheckboxArray = document.forms[0].elements[chkmodels[]]; The above should work. Is it really the first form on the page? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox arrays and validation
its the only form on the page... Based on the other responses I will have to use chkmodels[] and need to get the javascript working. Is it not possible to use the forms name when referencing the array? thank again. Angelo Marek Kilimajer [EMAIL PROTECTED] 10/5/2004 1:52:02 PM Angelo Zanetti wrote: Here is the OT part. how do I reference the checkboxes in javascript if the chkmodels[] is used? I have tried many things like: myCheckboxArray = document.forms[0].elements[chkmodels[]]; The above should work. Is it really the first form on the page? Disclaimer This e-mail transmission contains confidential information, which is the property of the sender. The information in this e-mail or attachments thereto is intended for the attention and use only of the addressee. Should you have received this e-mail in error, please delete and destroy it and any attachments thereto immediately. Under no circumstances will the Cape Technikon or the sender of this e-mail be liable to any party for any direct, indirect, special or other consequential damages for any use of this e-mail. For the detailed e-mail disclaimer please refer to http://www.ctech.ac.za/polic or call +27 (0)21 460 3911 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox arrays and validation
Angelo Zanetti wrote: its the only form on the page... Based on the other responses I will have to use chkmodels[] and need to get the javascript working. Is it not possible to use the forms name when referencing the array? You should be able to use: document.formName document.forms[0] document.forms['formName'] thank again. Angelo Marek Kilimajer [EMAIL PROTECTED] 10/5/2004 1:52:02 PM Angelo Zanetti wrote: Here is the OT part. how do I reference the checkboxes in javascript if the chkmodels[] is used? I have tried many things like: myCheckboxArray = document.forms[0].elements[chkmodels[]]; The above should work. Is it really the first form on the page? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox arrays and validation
Hi Marek, I try to access the array like this: document.frmft.elements[chkmodels[]]; but doesnt work. I also tried this: models = document.forms['frmft'].elements[chkmodels[]]; is there not a problem with the elements part? thanks Marek Kilimajer [EMAIL PROTECTED] 10/5/2004 2:19:26 PM Angelo Zanetti wrote: its the only form on the page... Based on the other responses I will have to use chkmodels[] and need to get the javascript working. Is it not possible to use the forms name when referencing the array? You should be able to use: document.formName document.forms[0] document.forms['formName'] thank again. Angelo Marek Kilimajer [EMAIL PROTECTED] 10/5/2004 1:52:02 PM Angelo Zanetti wrote: Here is the OT part. how do I reference the checkboxes in javascript if the chkmodels[] is used? I have tried many things like: myCheckboxArray = document.forms[0].elements[chkmodels[]]; The above should work. Is it really the first form on the page? Disclaimer This e-mail transmission contains confidential information, which is the property of the sender. The information in this e-mail or attachments thereto is intended for the attention and use only of the addressee. Should you have received this e-mail in error, please delete and destroy it and any attachments thereto immediately. Under no circumstances will the Cape Technikon or the sender of this e-mail be liable to any party for any direct, indirect, special or other consequential damages for any use of this e-mail. For the detailed e-mail disclaimer please refer to http://www.ctech.ac.za/polic or call +27 (0)21 460 3911 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox arrays and validation
On 05 October 2004 13:55, Angelo Zanetti wrote: Hi Marek, I try to access the array like this: document.frmft.elements[chkmodels[]]; but doesnt work. I also tried this: models = document.forms['frmft'].elements[chkmodels[]]; is there not a problem with the elements part? So long as your form goes something like: form name=frmft input type=checkbox name=chkmodels[] value=1Value 1br input type=checkbox name=chkmodels[] value=2Value 2br input type=checkbox name=chkmodels[] value=3Value 3br ... /form you can refer to the checkboxes simply as document.frmft[chkmodels[]] This is the way I've always done it, and it's always worked a treat. Of course, in this situation this will give you an array of checkbox objects which you then have to index into, but that's a whole other story. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox arrays and validation
thanks Mike, worked like a charm!! and thanks to the others who replied! Ford, Mike [EMAIL PROTECTED] 10/5/2004 3:09:32 PM On 05 October 2004 13:55, Angelo Zanetti wrote: Hi Marek, I try to access the array like this: document.frmft.elements[chkmodels[]]; but doesnt work. I also tried this: models = document.forms['frmft'].elements[chkmodels[]]; is there not a problem with the elements part? So long as your form goes something like: form name=frmft input type=checkbox name=chkmodels[] value=1Value 1br input type=checkbox name=chkmodels[] value=2Value 2br input type=checkbox name=chkmodels[] value=3Value 3br ... /form you can refer to the checkboxes simply as document.frmft[chkmodels[]] This is the way I've always done it, and it's always worked a treat. Of course, in this situation this will give you an array of checkbox objects which you then have to index into, but that's a whole other story. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Disclaimer This e-mail transmission contains confidential information, which is the property of the sender. The information in this e-mail or attachments thereto is intended for the attention and use only of the addressee. Should you have received this e-mail in error, please delete and destroy it and any attachments thereto immediately. Under no circumstances will the Cape Technikon or the sender of this e-mail be liable to any party for any direct, indirect, special or other consequential damages for any use of this e-mail. For the detailed e-mail disclaimer please refer to http://www.ctech.ac.za/polic or call +27 (0)21 460 3911 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox Question
Hi all, Im using php's cURL module to submit a form on a remote site. All is *good* so far but i dont know what parameter to pass to ensure that this checkbox is 'checked': INPUT TYPE=checkbox NAME=a VALUE=on so, what is it? a=what? Thanks very much! -- Nick W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Question
Hi Nick, Nick Wilson wrote: Hi all, [...] INPUT TYPE=checkbox NAME=a VALUE=on so, what is it? a=what? [...] if a was checked a=on is posted (or 'get'ed) if not checked a isn't set. Thanks very much! You're welcome Stephan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Question
Stephan Fiedler wrote: Hi Nick, Nick Wilson wrote: Hi all, [...] INPUT TYPE=checkbox NAME=a VALUE=on so, what is it? a=what? [...] if a was checked a=on is posted (or 'get'ed) if not checked a isn't set. Thanks very much! You're welcome Stephan that actually depends on the browser. Mayne browsers send a= when it's not checked (meaning an EMPTY value) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Question
* Thus wrote Nick Wilson: Hi all, Im using php's cURL module to submit a form on a remote site. All is *good* so far but i dont know what parameter to pass to ensure that this checkbox is 'checked': INPUT TYPE=checkbox NAME=a VALUE=on TIAS. a=value|on) which ever the browser seems appropriate. Curt -- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox
how can process only items with checked check-box? --- html --- html head titleUntitled Document/title /head body form name=form1 method=post action= p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[1] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[2] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[3] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[4] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[5] /p /form /body /html --- html ---
Re: [PHP] checkbox
Try foreach ($_POST['textfield'] as $num = $value); On Wed, 30 Jun 2004 15:56:35 +0800, Aris Santillan [EMAIL PROTECTED] wrote: how can process only items with checked check-box? --- html --- html head titleUntitled Document/title /head body form name=form1 method=post action= p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[1] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[2] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[3] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[4] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[5] /p /form /body /html --- html --- !DSPAM:40e26f26296421596418740! -- paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox
If you put square brackets after the name (e.g. var[]) your form should produce an array called $_POST[var] that comprises the checked boxes only. e.g. form method=post ... input type=checkbox name=var[] value=value1 input type=checkbox name=var[] value=value2 input type=checkbox name=var[] value=value3 Regards Alberto Brea [EMAIL PROTECTED] -Original Message- From: Aris Santillan [EMAIL PROTECTED] To: [EMAIL PROTECTED] Date: Wed, 30 Jun 2004 15:56:35 +0800 Subject: [PHP] checkbox how can process only items with checked check-box? --- html --- html head titleUntitled Document/title /head body form name=form1 method=post action= p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[1] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[2] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[3] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[4] /p p input type=checkbox name=checkbox value=checkbox input type=text name=textfield[5] /p /form /body /html --- html --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox: was it shown or not?
hi, if i understand well, a checkbox in a form is only send on to the next page when it is checked: so the next page will only see a value in $_POST['checkboxname'] if it is set: else it is not set. Right? So the followup page cannot see the difference between a form where the checkbox was not checked, and a form where the checkbox is not even there? thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox: was it shown or not?
At 19:16 17-7-03, you wrote: you understand it correctly ok so i really have to add another kludgy workaround to my form class :/ but thanks for confirming! Chris - Original Message - From: Chris Hayes (SENSE) [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 17, 2003 9:57 AM Subject: [PHP] checkbox: was it shown or not? hi, if i understand well, a checkbox in a form is only send on to the next page when it is checked: so the next page will only see a value in $_POST['checkboxname'] if it is set: else it is not set. Right? So the followup page cannot see the difference between a form where the checkbox was not checked, and a form where the checkbox is not even there? thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox: was it shown or not?
Chris Hayes (SENSE) wrote: if i understand well, a checkbox in a form is only send on to the next page when it is checked: so the next page will only see a value in $_POST['checkboxname'] if it is set: else it is not set. Right? So the followup page cannot see the difference between a form where the checkbox was not checked, and a form where the checkbox is not even there? Correct. This has little to do with PHP, though. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
Hello From a usability standpoint showing a checkbox that cannot be unchecked renders the checkbox obsolete. The consquence is not to show a checkbox at all. If you need an uncheckable checkbox because of licence aggreements or something like that. Or privacydeclaration type checkbox. Make it checkable but check on the server side if it is checked. If not render an error message to the client telling them why you can't process the form/data because the checkbox is unchecked. That way it is still up to the user to decide what he wants to do. Another alternative is to build a button that has to be pressed to continue which does the same as the checkbox. The important thing is: 1. Don't take away the users freedom of choice (checking / not checking) 2. Make the user feels he is in control (even though he isn't ;) ) 3. Only put up control elements that actually enable the user to take control Basically all three points are the same. I suggest to read up on usability issues. Just do a google on usability and software. Cause usability is one of the things most of the webprogrammers get wrong... It's not important what your intention is rather what the user intents to do! Please remember this is my opinion so take it or leave it. ;) Regards Stefan
Re: [PHP] Checkbox
On Thursday 27 March 2003 03:26, Reuben D. Budiardja wrote: But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway Also different browsers on different platforms render checkboxes differently so your users will get some odd looking checkboxes. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Torque is cheap. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
Tim Burden wrote: Just using the readonly flag in the input tag is the easiest method, I think. - Original Message - From: Reuben D. Budiardja [EMAIL PROTECTED] Newsgroups: php.general To: CPT John W. Holmes [EMAIL PROTECTED]; shaun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:26 PM Subject: Re: [PHP] Checkbox On Wednesday 26 March 2003 02:11 pm, CPT John W. Holmes wrote: On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway RDB I don't think showing a checkbox will clear things up for the user. Imagine, the use would probably get really annoyed not being able to check that god damn checkbox. I say put some text there instead. Eg. You can't do this, because of this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox
Hi, is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
On Wednesday 26 March 2003 09:16 am, shaun wrote: Hi, is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? When you write the page, if the checkbox is checked initially, write also a javascript to prevent it from being uncheck. Something like this: INPUT TYPE=CHECKBOX onClick=this.checked=true; CHECKED So everytime it's clicked, the javascript will make sure that it's checked again. HTH -RDB -- - /\ ASCII Ribbon Campaign against HTML \ / email and proprietary format X attachments. / \ - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. There are plenty of JavaScript or other workarounds you can do, but you still need to verify _everything_ on the server side and don't accept any changed value. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. There are plenty of JavaScript or other workarounds you can do, but you still need to verify _everything_ on the server side and don't accept any changed value. Of course, that's obvious. I see the question from the user interface point of view. Functionally, the javascript doesn't do anything, except give the original poster what he wants. RDB -- - /\ ASCII Ribbon Campaign against HTML \ / email and proprietary format X attachments. / \ - Have you been used by Microsoft today? Choose your life. Choose freedom. Choose LINUX. - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
On Wednesday 26 March 2003 02:11 pm, CPT John W. Holmes wrote: On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway RDB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
Just using the readonly flag in the input tag is the easiest method, I think. - Original Message - From: Reuben D. Budiardja [EMAIL PROTECTED] Newsgroups: php.general To: CPT John W. Holmes [EMAIL PROTECTED]; shaun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:26 PM Subject: Re: [PHP] Checkbox On Wednesday 26 March 2003 02:11 pm, CPT John W. Holmes wrote: On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway RDB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox
I agree...and like John said, as long as you don't accept any changes when you process the form you should be good to go... -Original Message- From: Tim Burden [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:25 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Checkbox Just using the readonly flag in the input tag is the easiest method, I think. - Original Message - From: Reuben D. Budiardja [EMAIL PROTECTED] Newsgroups: php.general To: CPT John W. Holmes [EMAIL PROTECTED]; shaun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:26 PM Subject: Re: [PHP] Checkbox On Wednesday 26 March 2003 02:11 pm, CPT John W. Holmes wrote: On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway RDB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox
But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway Yeah, really doesn't matter how you do it, I guess. Just so long as you check the data after it's submitted again and determine whether the value should have been allowed to change or not. If it wasn't allowed to change, then don't accept the value that was passed (because it may of changed regardless of what measures you take). Like you said, hopefully that part is obvious, though. :) ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox
Just be wary that not all browsers will honor the readonly flag (Netscape 4 for example). In looking at this I found a tutorial at http://www.estek.net/estek/idocs/forms/_INPUT_DISABLED.html . I tested it in IE 6, NS 7.02 and Opera 7. None of these browsers prevented me from checking and unchecking the box. Only the DISABLED flag does. Readonly apparently prevents the user from altering the value of the input field. -Original Message- From: Tim Burden [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 11:25 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Checkbox Just using the readonly flag in the input tag is the easiest method, I think. - Original Message - From: Reuben D. Budiardja [EMAIL PROTECTED] Newsgroups: php.general To: CPT John W. Holmes [EMAIL PROTECTED]; shaun [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, March 26, 2003 2:26 PM Subject: Re: [PHP] Checkbox On Wednesday 26 March 2003 02:11 pm, CPT John W. Holmes wrote: On Wednesday 26 March 2003 01:43 pm, CPT John W. Holmes wrote: is it possible to have a checkbox that if it is specified to be checked when the page is being formulated then it cannot be unchecked? No. No... No. If you already know you don't want it to be unchecked, then don't show a checkbox. That's why we have PHP, so you can create your page DYNAMICALLY and not show bits and pieces when you don't need to. Although that is theoretically correct, there can be some reason why one would want to display a checkbox anyway. Sometimes it can be clearer for the user to see the GUI, asthetic reason, etc, etc. True. In that case, though, I would just show an image of a checked check box. The end result will be the same to the user, they will just think it's a checkbox they cannot uncheck. But isn't it so much easier to type in that one line HTML + javascript than trying to get an image of a checked check box.. unless you have that handy, you'd have to eg. take a snapshot, or draw something, then save the file as an image file...hmm... and as you said, the effect will be the same to the user anyway RDB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox
hello, how can i get the output file from the curl function to stream - to be processed like from fopen or fsockopen? thanks... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox related...
Hi everybody, I have a form with 5 checkboxes. I want to make sure that a user checks atleast 2 boxes before he can proceed. How can that be made possible. Thank you -Dhaval _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox related...
At 19:57 16.02.2003, Dhaval Desai said: [snip] I have a form with 5 checkboxes. I want to make sure that a user checks atleast 2 boxes before he can proceed. How can that be made possible. [snip] You have 2 options: 1) Client-side JavaScript: in the forms OnSubmit handler, loop your checkboxes and make sure at least 2 are checked. If the precondition is not met, return false from the onSubmit handler. 2) Server-Side via PHP: make an array of all available checkboxes, and walk this array to see if you have at least 2 of these checkboxes set in your $_REQUEST array. If the precondition is not met, retransmit the original form without proceeding. I'd prefer a combination of both - the JS method saves the user an unnecessary form transmission, speeding up his entry. The server-side script method makes sure there's no malicious user trying to trick the system *g* -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox related...
How do we do it using the first option i.e javascript to count how many boxes are checked...could you give some example... Thanx -Dhaval From: David McInnis [EMAIL PROTECTED] To: 'Dhaval Desai' [EMAIL PROTECTED] Subject: RE: [PHP] Checkbox related... Date: Sun, 16 Feb 2003 10:59:17 -0800 You can use javascript to count the number of items checked or you can check the size of your array once the form has been submitted to the server. David -Original Message- From: Dhaval Desai [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 16, 2003 10:58 AM To: [EMAIL PROTECTED] Subject: [PHP] Checkbox related... Hi everybody, I have a form with 5 checkboxes. I want to make sure that a user checks atleast 2 boxes before he can proceed. How can that be made possible. Thank you -Dhaval _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox related...
At 20:34 16.02.2003, Dhaval Desai said: [snip] How do we do it using the first option i.e javascript to count how many boxes are checked...could you give some example... [snip] Warning - untested: script language=JavaScript function validateChecks() { aboxes = Array('box1','box2','box3','box4','box5'); hF = document.forms['myform']; if (hF) { for (i = 0, count=0; i aboxes.length; i++) { hBox = hF.elements[aboxes[i]]; if (hBox.checked) { ++count; if (count = 2) return true; } } } return false; } /script form name=myform onSubmit=validateChecks() input type=checkbox name=box1 value=1 input type=checkbox name=box2 value=1 input type=checkbox name=box3 value=1 input type=checkbox name=box4 value=1 input type=checkbox name=box5 value=1 input type=submit /form I believe you get the idea... -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql, php, checkbox
Indeed, now it works, I put the form tag by mistake... Thanks, Adrian - Original Message - From: rija [EMAIL PROTECTED] To: Adrian Partenie [EMAIL PROTECTED] Sent: Tuesday, December 03, 2002 11:30 PM Subject: Re: [PHP] mysql, php, checkbox There are form/form tags around input type=checkbox ... What are they supposed to do? I think your problem lies there, because ids[] belong to this new form not to the first one and then ids[] cannot be set. Secondly, method='post' inside input does nothing. Hope that helps. - Original Message - From: Adrian Partenie [EMAIL PROTECTED] To: php [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 4:50 AM Subject: Re: [PHP] mysql, php, checkbox It works, but just for the first row selected from the table. I think that the problem is that the checkboxes are declared inside a while loop. If i declare manually all checkboxes it works. Any ideas ? Or maybe I'm doing something wrong? echo form method=\post\ action=\selectare.php?ids[]\; echo input type=\Submit\ value=\Trimite\; /* Connecting, selecting database */ $link = mysql_connect(localhost, root, adrian) or die(Could not connect); print Connected successfully; mysql_select_db(menagerie) or die(Could not select database); /* Performing SQL query */ $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\ids[]\ value=\{$row['id']}\/form/td; echo tda href=\lowerframe.php?id={$row['id']}\ target=\lowerframe\{$row['id']}/a/td; echo td{$row['subject']}/td; echo td{$row['open']}/td; echo td{$row['close']}/td/tr; } echo /table; /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); echo /form; ? ### //selectare.php (just displays the id's of selected checkboxes) //$useri=$_POST['useri']; $ids=$_POST['ids']; reset($ids); while (list ($key, $value) = each ($ids)) { echo $valuebr /\n; } ? # As I said, when I select the first checkbox, I get the id, but when I select any other checkbox, I get the errors PHP Notice: Undefined index: ids in selectare.php PHP Warning: Variable passed to each() is not an array or object in selectare.php - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Adrian Partenie' [EMAIL PROTECTED]; 'php' [EMAIL PROTECTED] Sent: Thursday, November 28, 2002 5:54 PM Subject: RE: [PHP] mysql, php, checkbox I'm displaying the content of a mysql table with autoincrement index. I want to be able to select the each row from the table using the check boxes. In order to do that, i want to assign to each checkbox the name=index of selected row. I assign to the checkboxes the value of selected id, but I can't retreiveit later for further processing. My code looks like this $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr ; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\{$row['id']}\/form/td; // ?? It looks like your naming it as a number, which won't work for PHP. You want to name all of your checkboxes the same, with a [] on the name to make the results an array in PHP. ... name=id[] value={$row['id']} Then, you'll have $_POST['id'][x] as an array in PHP. Only the checkboxes that were selected will be in the array, from zero to however many were checked. The value of $_POST['id'][x] will be whatever was in the value=... part of the HTML checkbox... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql, php, checkbox
It works, but just for the first row selected from the table. I think that the problem is that the checkboxes are declared inside a while loop. If i declare manually all checkboxes it works. Any ideas ? Or maybe I'm doing something wrong? echo form method=\post\ action=\selectare.php?ids[]\; echo input type=\Submit\ value=\Trimite\; /* Connecting, selecting database */ $link = mysql_connect(localhost, root, adrian) or die(Could not connect); print Connected successfully; mysql_select_db(menagerie) or die(Could not select database); /* Performing SQL query */ $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\ids[]\ value=\{$row['id']}\/form/td; echo tda href=\lowerframe.php?id={$row['id']}\ target=\lowerframe\{$row['id']}/a/td; echo td{$row['subject']}/td; echo td{$row['open']}/td; echo td{$row['close']}/td/tr; } echo /table; /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); echo /form; ? ### //selectare.php (just displays the id's of selected checkboxes) //$useri=$_POST['useri']; $ids=$_POST['ids']; reset($ids); while (list ($key, $value) = each ($ids)) { echo $valuebr /\n; } ? # As I said, when I select the first checkbox, I get the id, but when I select any other checkbox, I get the errors PHP Notice: Undefined index: ids in selectare.php PHP Warning: Variable passed to each() is not an array or object in selectare.php - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Adrian Partenie' [EMAIL PROTECTED]; 'php' [EMAIL PROTECTED] Sent: Thursday, November 28, 2002 5:54 PM Subject: RE: [PHP] mysql, php, checkbox I'm displaying the content of a mysql table with autoincrement index. I want to be able to select the each row from the table using the check boxes. In order to do that, i want to assign to each checkbox the name=index of selected row. I assign to the checkboxes the value of selected id, but I can't retreiveit later for further processing. My code looks like this $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr ; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\{$row['id']}\/form/td; // ?? It looks like your naming it as a number, which won't work for PHP. You want to name all of your checkboxes the same, with a [] on the name to make the results an array in PHP. ... name=id[] value={$row['id']} Then, you'll have $_POST['id'][x] as an array in PHP. Only the checkboxes that were selected will be in the array, from zero to however many were checked. The value of $_POST['id'][x] will be whatever was in the value=... part of the HTML checkbox... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysql, php, checkbox
Hello, I'm displaying the content of a mysql table with autoincrement index. I want to be able to select the each row from the table using the check boxes. In order to do that, i want to assign to each checkbox the name=index of selected row. I assign to the checkboxes the value of selected id, but I can't retreiveit later for further processing. My code looks like this $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\{$row['id']}\/form/td; // ?? echo tda href=\lowerframe.php?id={$row['id']}\ target=\lowerframe\{$row['id']}/a/td; //for other purposes, it works fine echo td{$row['subject']}/td; echo td{$row['open']}/td; echo td{$row['close']}/td/tr; } echo /table; Any sugestions if i want to use forms, something like form method=post action=selectare.php?id=$row['id'] input type=Submit value=Trimite /form Thanks, Adrian
RE: [PHP] mysql, php, checkbox
I'm displaying the content of a mysql table with autoincrement index. I want to be able to select the each row from the table using the check boxes. In order to do that, i want to assign to each checkbox the name=index of selected row. I assign to the checkboxes the value of selected id, but I can't retreiveit later for further processing. My code looks like this $query = SELECT * FROM reclamatie; $result = mysql_query($query) or die(Query failed); /* Printing results in HTML */ echo table border=1; echo trtd/tdtdID/tdtdSubject/tdtdOpen/tdtdClose/td/tr ; while($row = MySQL_fetch_array($result)) { echo trtdforminput type=\checkbox\ method=\post\ name=\{$row['id']}\/form/td; // ?? It looks like your naming it as a number, which won't work for PHP. You want to name all of your checkboxes the same, with a [] on the name to make the results an array in PHP. ... name=id[] value={$row['id']} Then, you'll have $_POST['id'][x] as an array in PHP. Only the checkboxes that were selected will be in the array, from zero to however many were checked. The value of $_POST['id'][x] will be whatever was in the value=... part of the HTML checkbox... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox objects returning false for isset() when submitted via a form.
Hi, I have a form that submits to itself via: form name=hsform method=POST action=?=$_SERVER['PHP_SELF'] ? Within my form, I have some checkbox objects. If I check them and submit my form, isset(variable) returns true. However, if I do not check them and submit my form, isset(variable) returns false. I am confused as I though that isset() returns true if the variable exists regardless if it is empty or not. Is there a way to do what I want? Using php 4.2.1 on RedHat Linux 6.2 Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox objects returning false for isset() when submittedvia a form.
On Tue, 1 Oct 2002, DonPro wrote: Within my form, I have some checkbox objects. If I check them and submit my form, isset(variable) returns true. However, if I do not check them and submit my form, isset(variable) returns false. I am confused as I though that isset() returns true if the variable exists regardless if it is empty or not. Is there a way to do what I want? Checkbox values are only sent if they are on (checked). http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.2 ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox question
If you cannot use square brackets, get the values yourself from $_SERVER['QUERY_STRING'] Alex Shi wrote: How to ontain data from a group of checkbox using same name? For example, in a form there're 6 checkboxes and all named as Interesting_Area. I know if put a pairs of square brackets at the end of the name then in php all the values of them can be ontained. However, for some reason I cannot use square brackets. Please help me out if anyone know how to do the trick. THanks! Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox question
Thanks for your reply! I tested $_SERVER['QUERY_STRING']. Seems like it only return the string for get method but not for post. Any idea? Alex Marek Kilimajer [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... If you cannot use square brackets, get the values yourself from $_SERVER['QUERY_STRING'] Alex Shi wrote: How to ontain data from a group of checkbox using same name? For example, in a form there're 6 checkboxes and all named as Interesting_Area. I know if put a pairs of square brackets at the end of the name then in php all the values of them can be ontained. However, for some reason I cannot use square brackets. Please help me out if anyone know how to do the trick. THanks! Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox question
How to ontain data from a group of checkbox using same name? For example, in a form there're 6 checkboxes and all named as Interesting_Area. I know if put a pairs of square brackets at the end of the name then in php all the values of them can be ontained. However, for some reason I cannot use square brackets. Please help me out if anyone know how to do the trick. THanks! Alex -- --- TrafficBuilder Network: http://www.bestadv.net/index.cfm?ref=7029 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP checkbox/hidden field question
I am executing the follwoing statement as part of a while loop. This is part of a form and I wish to pass the name and value of the checkbox as a hidden field only is the checkbox is checked. Can you suggest how I can accomplish this task? tdinput type=checkbox name=d_c_arr[] value=?php echo $db-f(order_id) ?/td As you might know, checkboxes don't have the VALUE attribute. HTML won't even submit the VALUE attribute to the next page. You will only have an array containing 0's and 1's, the results of the checkboxes. So, on the next page, you will have to lookup the values again. Then print the hidden input's to the page in a for loop, while looping trough $d_c_arr. HTH Erwin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: PHP checkbox/hidden field question
you need to define the key for checkbox arrays in order to distinguish them (as only the checked ones will be posted).. something like ... tdinput type=checkbox name=d_c_arr[?php echo($count++); ?]/td Tim Ward www.chessish.com -Original Message- From: Paul Maine [mailto:[EMAIL PROTECTED]] Sent: 02 September 2002 00:56 To: PHP PHP Subject: PHP checkbox/hidden field question I am executing the follwoing statement as part of a while loop. This is part of a form and I wish to pass the name and value of the checkbox as a hidden field only is the checkbox is checked. Can you suggest how I can accomplish this task? tdinput type=checkbox name=d_c_arr[] value=?php echo $db-f(order_id) ?/td Thank You Paul php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP checkbox/hidden field question
You are wrong, this is from HTML 4.01 specification: value = /cdata/ cid:[EMAIL PROTECTED] [CA] cid:[EMAIL PROTECTED] This attribute specifies the initial value cid:[EMAIL PROTECTED] of the control. It is optional except when the type cid:[EMAIL PROTECTED] attribute has the value radio or checkbox. Upon submiting a form, only successfull checkboxes are submited, so on the next page you only need this loop: foreach($d_c_arr as $i) { echo 'input type=hidden name=d_c_arr[] value='. htmlspecialchars($i).''; } $d_c_arr contains only checked checkboxes. Marek Erwin wrote: I am executing the follwoing statement as part of a while loop. This is part of a form and I wish to pass the name and value of the checkbox as a hidden field only is the checkbox is checked. Can you suggest how I can accomplish this task? tdinput type=checkbox name=d_c_arr[] value=?php echo $db-f(order_id) ?/td As you might know, checkboxes don't have the VALUE attribute. HTML won't even submit the VALUE attribute to the next page. You will only have an array containing 0's and 1's, the results of the checkboxes. So, on the next page, you will have to lookup the values again. Then print the hidden input's to the page in a for loop, while looping trough $d_c_arr. HTH Erwin
RE: [PHP] Re: PHP checkbox/hidden field question
Some check box info here too: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20117420.html - Victor www.argilent.com -Original Message- From: Marek Kilimajer [mailto:[EMAIL PROTECTED]] Sent: Monday, September 02, 2002 7:24 AM To: PHP Subject: Re: [PHP] Re: PHP checkbox/hidden field question You are wrong, this is from HTML 4.01 specification: value = /cdata/ cid:[EMAIL PROTECTED] [CA] cid:[EMAIL PROTECTED] This attribute specifies the initial value cid:[EMAIL PROTECTED] of the control. It is optional except when the type cid:[EMAIL PROTECTED] attribute has the value radio or checkbox. Upon submiting a form, only successfull checkboxes are submited, so on the next page you only need this loop: foreach($d_c_arr as $i) { echo 'input type=hidden name=d_c_arr[] value='. htmlspecialchars($i).''; } $d_c_arr contains only checked checkboxes. Marek Erwin wrote: I am executing the follwoing statement as part of a while loop. This is part of a form and I wish to pass the name and value of the checkbox as a hidden field only is the checkbox is checked. Can you suggest how I can accomplish this task? tdinput type=checkbox name=d_c_arr[] value=?php echo $db-f(order_id) ?/td As you might know, checkboxes don't have the VALUE attribute. HTML won't even submit the VALUE attribute to the next page. You will only have an array containing 0's and 1's, the results of the checkboxes. So, on the next page, you will have to lookup the values again. Then print the hidden input's to the page in a for loop, while looping trough $d_c_arr. HTH Erwin __ Post your ad for free now! http://personals.yahoo.ca -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP checkbox/hidden field question
Marek Kilimajer wrote: You are wrong, this is from HTML 4.01 specification: You're right. Thanks for your reply! Grtz Erwin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP checkbox/hidden field question
I am executing the follwoing statement as part of a while loop. This is part of a form and I wish to pass the name and value of the checkbox as a hidden field only is the checkbox is checked. Can you suggest how I can accomplish this task? tdinput type=checkbox name=d_c_arr[] value=?php echo $db-f(order_id) ?/td Thank You Paul php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox question
I have a page with a checkbox, when i submit to the next page the variable $whatever (the checkboxes name.) will be On if its checked, and it will be undefined if its not checked. Shouldn't it be a empty string? and not undefined? /José -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox question
On Friday 16 August 2002 17:54, José Jeria wrote: I have a page with a checkbox, when i submit to the next page the variable $whatever (the checkboxes name.) will be On if its checked, and it will be undefined if its not checked. Shouldn't it be a empty string? and not undefined? That is how it works. If it's not checked it does not get defined. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* We cannot command nature except by obeying her. -- Sir Francis Bacon */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox question
Hmmm, then the book Beginning PHP from Wrox is wrong... /J Jason Wong wrote: On Friday 16 August 2002 17:54, José Jeria wrote: I have a page with a checkbox, when i submit to the next page the variable $whatever (the checkboxes name.) will be On if its checked, and it will be undefined if its not checked. Shouldn't it be a empty string? and not undefined? That is how it works. If it's not checked it does not get defined. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox = POST = array??
I'm doing something very similar on a project I'm working on, except I'm using radio buttons. I'm not quite sure what are using the ID for (for style sheets or a data ID). If you are using it as a data ID, then you can make it part of the topic[] array. So it would look like this: input type='checkbox' name=topic['45'] value='a value' Then to process the array, you would do something like this: while (list($checkboxID,$checkboxValue) = each $topic) { // Your process code } Each check box is then referenced by the two variables $checkboxID and $checkboxValue. There are a number of ways ou can do this, really any way you would process and array (i.e. foreach). I prefer this way because I can give logical names to the array elements I am using. On Saturday, August 10, 2002, at 02:56 PM, PeterV wrote: I, I don't have my books here and it's been a while since I did PHP, and google isn't helping: How do I code a bunch of checkboxes with id's, and then loop trough the result as an array after POSTing it? What I have now: input type='checkbox' id='45' name='topic[]' value='45' doesn't return an array $topic?? Thanks, Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox = POST = array??
I, I don't have my books here and it's been a while since I did PHP, and google isn't helping: How do I code a bunch of checkboxes with id's, and then loop trough the result as an array after POSTing it? What I have now: input type='checkbox' id='45' name='topic[]' value='45' doesn't return an array $topic?? Thanks, Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox = POST = array??
On Sat, Aug 10, 2002 at 02:56:48PM -0400, PeterV wrote: What I have now: input type='checkbox' id='45' name='topic[]' value='45' doesn't return an array $topic?? Probaby due to register_globals. It should exist in $_POST['topic'] -- Jason Stechschulte [EMAIL PROTECTED] http://www.ypisco.com -- I am a bookaholic. If you are a decent person, you will not sell me another book. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checkbox Initial Value based on record in db
Kinda off topic here, just checking to see If I am on the right track with this input type=checkbox name=abb value=?php echo $myrow['abb'] ? the result should be : IF the record contains the field abb and it has a value of 1 then it will be checked off for viewing. Brainfarting all day !! Thank You Daniel Negrón Lotus Notes Administrator / Developer KB Electronics, Inc. 954.346.4900x122 http://www.kbelectronics.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Initial Value based on record in db
On Wed, 1 May 2002, Daniel Negron/KBE wrote: Kinda off topic here, just checking to see If I am on the right track with this input type=checkbox name=abb value=?php echo $myrow['abb'] ? the result should be : IF the record contains the field abb and it has a value of 1 then it will be checked off for viewing. http://www.w3.org/TR/REC-html32#fields input type=checkbox name=abb value=1 checked input type=checkbox name=abb value=1 miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checkbox Initial Value based on record in db
It will only be checked if you put CHECKED in your HTML. if($myrow['abb'] == 1) { echo checked ; } Add that into your input element. ---John Holmes... - Original Message - From: Daniel Negron/KBE [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 01, 2002 1:04 PM Subject: [PHP] Checkbox Initial Value based on record in db Kinda off topic here, just checking to see If I am on the right track with this input type=checkbox name=abb value=?php echo $myrow['abb'] ? the result should be : IF the record contains the field abb and it has a value of 1 then it will be checked off for viewing. Brainfarting all day !! Thank You Daniel Negrón Lotus Notes Administrator / Developer KB Electronics, Inc. 954.346.4900x122 http://www.kbelectronics.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Checkbox Initial Value based on record in db
Kinda off topic here, just checking to see If I am on the right track with this input type=checkbox name=abb value=?php echo $myrow['abb'] ? the result should be : IF the record contains the field abb and it has a value of 1 then it will be checked off for viewing. No, that wouldn't workto have a checkbox autochecked the HTML must be similar to input type=checkbox name=abb value=?php echo $myrow['abb']; ? checked So a sample coding might be input type=checkbox name=abb value=?php echo $myrow['abb']; ? ?php if ($myrow['abb']) { echo 'checked'; } ? Sincerely, Craig Vincent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] checkbox doesn't pass?
I have a html form with some text (T1) and checkbox (C1) fields to pass it to a php script. Accessing text fields has no problem. There is a problem when I use $C1=$HTTP_POST_VARS['C1'] to take the value of C1 (ON) If it is not checked, then it is not set at all. (??why??) So I use : if (!isset($C1)) { $C1=0 } but still I get an warning that C1 is not set, on my screen. That happens before the use of isset function. How can I susspent this warning message? What's wrong? Makis Savaidis Thessaloniki Greece -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox doesn't pass?
At 04.04.2002 15:23, you wrote: I have a html form with some text (T1) and checkbox (C1) fields to pass it to a php script. Accessing text fields has no problem. There is a problem when I use $C1=$HTTP_POST_VARS['C1'] to take the value of C1 (ON) If it is not checked, then it is not set at all. (??why??) So I use : if (!isset($C1)) { $C1=0 } but still I get an warning that C1 is not set, on my screen. That happens before the use of isset function. How can I susspent this warning message? Makis, why do you use $HTTP_POST_VARS? Do I miss something? if you have a form and send it, the vars have the same names as in your form, will say if your checkbox name=foo value=someval will be transmitted, then in the following page there´s a var named $foo. and the value will be someval if the box is checked, otherwise there´s no (or NULL or FALSE ???) value in it. I personally prefer put checkbox vars (if there are several) in an array f.e. $foo[] In the following page I just scan the array and if there´s a value in a field thats fine. HTH Oliver -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox doesn't pass?
On Thursday 04 April 2002 20:46, [EMAIL PROTECTED] wrote: why do you use $HTTP_POST_VARS? Do I miss something? For security reasons. Manual Security -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Above all things, reverence yourself. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox doesn't pass?
Thank you both for help and info! You were both very fast :) I didn't know I could not to use $HTTP_POST_VARS . Now it works all right. But IF I still want to use $HTTP_POST_VARS, what then? What about the warning when checkbox is not checked? Thanks Makis -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 5:51 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] checkbox doesn't pass? On Thursday 04 April 2002 20:46, [EMAIL PROTECTED] wrote: why do you use $HTTP_POST_VARS? Do I miss something? For security reasons. Manual Security -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Above all things, reverence yourself. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox doesn't pass?
At 18:17 04-04-02 +0300, savaidis wrote: But IF I still want to use $HTTP_POST_VARS, what then? What about the warning when checkbox is not checked? I use empty() to check the for the existence of checkbox variables. -- - Eugene Mah, M.Sc., DABR [EMAIL PROTECTED] Medical Physicist/Misplaced Canuck[EMAIL PROTECTED] Department of Radiology For I am a Bear of Very Little Medical University of South Carolina Brain, and long words Bother Charleston, South Carolina me. Winnie the Pooh http://home.netcom.com/~eugenem/ PGP KeyID = 0x1F9779FD, 0x319393F4 PGP keys available on request ICQ 3113529 O- - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] checkbox doesn't pass?
You should use $HTTP_POST_VARS (or $_POST) all of the time. There's security risks in using register_globals. It's not risky in all cases. But register_globals will allow arbitrary variables to be added to into the name space of your script by simply putting them on the uri. Code not expecting such input, and expecting variables not to exist unless the script set them may behave unexpectedly. The reason the variable is not set is that the checkbox isn't checked. You can test the variable with isset(), or empty() before you use it so you don't get the warning. To learn what your script it seeing when you submit the page, do a: foreach ($HTTP_POST_VARS as $key = $value) { echo Key: $key Value: $valuebr\n; } at the top of your action handler script, and watch the variables come in when you check or not check the checkboxes. Once you understand that, then write the code to handle the situation. -Original Message- From: savaidis [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 10:17 AM Thank you both for help and info! You were both very fast :) I didn't know I could not to use $HTTP_POST_VARS . Now it works all right. But IF I still want to use $HTTP_POST_VARS, what then? What about the warning when checkbox is not checked? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox doesn't pass?
But IF I still want to use $HTTP_POST_VARS, what then? What about the warning when checkbox is not checked? I use empty() to check the for the existence of checkbox variables. You can also use isset(); Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox doesn't pass?
Unchecked checkboxes pass no values, that's how it works. It's either set or not. Default value for a checkbox is 'on' although you can change that. isset() will work fine. Regards, Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] checkbox validation
Hi jacky, put an empty square bracket after the variable name as follows: input type=checkbox name=id[ ] value=$id assuming that your above statement is in a loop we will have following structure: * form input type=checkbox name=id[ ] value=$id input type=checkbox name=id[ ] value=$id input type=checkbox name=id[ ] value=$id etc... submit button /form now when you submit the form, an array named id[ ] will be posted . this array will contain the number of elements/checkbox which were checked on. so out of 25 checkboxes if you select only 5 checkboxes, then the size of the array id[ ] will be only 5. so with another loop you can retrieve all the values as follows: *** $i=0; while($isizeof($id): $id[$i]==blah; $i++; endwhile; *** sorry for the poor explanation but i hope this will serve your purpose. if you have any queries with this feel free to contact me. regards keyur $$$ - Original Message - From: Jacky [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, April 19, 2001 1:13 AM Subject: [PHP] checkbox validation Hi all I have a form with the checkbox like this form $query=select id from foo; $result=($query,$con); while ($row = mysql_fetch_array($result)) { input type=checkbox name=$id value=on } submit button and stuffs here... /form After I submit to next page, at next page, how do I check which check box is checked? like this? if ($id==on) { do something }else{ do something } I did try this but did not work, what am i suppose to do to achieve this? Jack [EMAIL PROTECTED] There is nothing more rewarding than reaching the goal you set for yourself -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] checkbox validation
Hi all I have a form with the checkbox like this form $query="select id from foo"; $result=($query,$con); while ($row = mysql_fetch_array($result)) { input type="checkbox" name="$id" value="on" } submit button and stuffs here... /form After I submit to next page, at next page, how do I check which check box is checked? like this? if ($id=="on") { do something }else{ do something } I did try this but did not work, what am i suppose to do to achieve this? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself"
RE: [PHP] checkbox validation
After I submit to next page, at next page, how do I check which check box is checked? like this? if ($id=="on") { do something }else{ do something } Hi try this assuming you have no toher check boxes called $id if(isset($id)) { do something }else{ do other } M@ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] checkbox validation
Jacky wrote: Hi all I have a form with the checkbox like this form $query="select id from foo"; $result=($query,$con); while ($row = mysql_fetch_array($result)) { input type="checkbox" name="$id" value="on" } submit button and stuffs here... /form One possibility: Add a hidden field in the form and write all names of the checkboxes in it, separated by a semicolon, for example. - form $query="select id from foo"; $result=($query,$con); while ($row = mysql_fetch_array($result)) { input type="checkbox" name="$id" value="on" $names_of_checkboxes.=$id.";"; } input type="hidden" name="names_of_checkboxes" value="? echo $names_of_checkboxes; ?" submit button and stuffs here... /form --- Then, in the next page you just do following: --- $checkboxes_names_array=explode(";",$names_of_checkboxes); for($x=0;xcount($checkboxes_names_array);$x++) { if($$checkboxes_names_array[$x]=="on") // box checked } --- Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]