Re: [PHP] parsing select multiple=multiple

2013-02-21 Thread Jim Giner




I *have* heard claims that something like this is preferrable, though:

if (FALSE === $variable)

I believe I read a comment somewhere once that writing your IF 
statements that way helped to trigger an error message when the coder 
forgot to use the double equal sign (==) in the statement.  I haven't 
adopted it yet, but I think that's the sole reason for it.  Basically 
you can't make an assignment (=) to a constant or some non-variable target.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-21 Thread tamouse mailing lists
On Thu, Feb 21, 2013 at 8:46 AM, Jim Giner jim.gi...@albanyhandball.com wrote:


 I *have* heard claims that something like this is preferrable, though:

 if (FALSE === $variable)

 I believe I read a comment somewhere once that writing your IF statements
 that way helped to trigger an error message when the coder forgot to use the
 double equal sign (==) in the statement.  I haven't adopted it yet, but I
 think that's the sole reason for it.  Basically you can't make an assignment
 (=) to a constant or some non-variable target.

That sounds like a reasonable explanation to me.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread Tedd Sperling
On Feb 18, 2013, at 7:54 PM, John Taylor-Johnston 
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 I am capable with select name=DPRpriority. (I suppose I did it correctly? 
 :p )
 But I haven't the first clue how to parse a select multiple and multiply 
 select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

John:

A clue? How about an example? 

See here:

http://sperling.com/php/select/index.php

Cheers,

tedd

_
t...@sperling.com
http://sperling.com



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread Jim Giner

On 2/20/2013 11:41 AM, Tedd Sperling wrote:

On Feb 18, 2013, at 7:54 PM, John Taylor-Johnston 
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:


I am capable with select name=DPRpriority. (I suppose I did it correctly? 
:p )
But I haven't the first clue how to parse a select multiple and multiply select 
name=DPRtype.
Would anyone give me a couple of clues please? :)
Thanks,
John


John:

A clue? How about an example?

See here:

http://sperling.com/php/select/index.php

Cheers,

tedd

_
t...@sperling.com
http://sperling.com



Try googling it.  It's out there.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-20 Thread tamouse mailing lists
On Tue, Feb 19, 2013 at 1:02 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

 tamouse mailing lists wrote:

 I hate arrays. :D

 Here's a small snippet showing how it works, I hope:

 foreach ($DPRpriority as $item = $value) {
echo li .$item.: .$value['name']. selected:
 .$value['selected']. /li\n;
 }

 Question 1: when did we have to add [] to a input name to turn it into an
 array?

 input type=checkbox name=DPRlocationdetails[] value=Unknown

 According to phpinfo() it still comes out as $_POST['DPRlocationdetails']
 without [].

 Are the [] necessary?

[] are necessary when you want to return multiple values for a form
field, or collection of form fields such as checkbox. AFAIK, this has
always been the case with PHP. See
https://gist.github.com/tamouse/5002728

 --
 Question 2:
 I was looking at some code in the Manual, where someone used isset and
 is_array.

 How necessary is if(isset($_POST['DPRlocationdetails']))

 and then to use: if(is_array($_POST['DPRlocationdetails']))

 That seems like over kill?

It's more defensive, in the case where someone may be by-passing your
form to send things in.

 --
 Question 3:

 My code works, perfectly.

Then there must be no questions. :)

 In this case, I decided to attack some check-boxes
 first. The resulting function will work for select multiple too..

 Does anyone see me doing something wrong in my code below?

 My questions are:

 Is this the only way to pass Unknown, Family Home or Apartment into
 the function?

 Is this correct?

  if ($_POST['DPRlocationdetails'] == Unknown)

 Somebody once told me I had to do it this way?

  if (Unknown == $_POST['DPRlocationdetails'])

In this scenario, these are equivalent. There is no preference of one
over the other.

I *have* heard claims that something like this is preferrable, though:

if (FALSE === $variable)

But I think that may have been due to some misunderstanding of
precedences in the following sort of scenario:

if (FALSE === ($result = some_function())

where if done this way:

if ($result = some_function() === FALSE)

was giving them bad results.

 John

 snip---

 form action=foo.php id=DPRform method=postinput value=Update
 type=submit
 input type=checkbox name=DPRlocationdetails[] value=Unknown ?php
 filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
 input type=checkbox name=DPRlocationdetails[] value=Family Home ?php
 filter_value($_POST['DPRlocationdetails'],Family Home); ? Family Home
 input type=checkbox name=DPRlocationdetails[] value=Apartment ?php
 filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment
 /form

 ?php
 function filter_value($tofilter,$tofind) {
 foreach($tofilter as $value){
 if ($value == $tofind) echo checked;
 }
 }
 ?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-19 Thread John Taylor-Johnston


tamouse mailing lists wrote:

I hate arrays. :D

Here's a small snippet showing how it works, I hope:

foreach ($DPRpriority as $item = $value) {
   echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}

Question 1: when did we have to add [] to a input name to turn it into 
an array?


input type=checkbox name=DPRlocationdetails[] value=Unknown

According to phpinfo() it still comes out as 
$_POST['DPRlocationdetails'] without [].


Are the [] necessary?
--
Question 2:
I was looking at some code in the Manual, where someone used isset and 
is_array.


How necessary is if(isset($_POST['DPRlocationdetails']))

and then to use: if(is_array($_POST['DPRlocationdetails']))

That seems like over kill?
--
Question 3:

My code works, perfectly. In this case, I decided to attack some 
check-boxes first. The resulting function will work for select 
multiple too..


Does anyone see me doing something wrong in my code below?

My questions are:

Is this the only way to pass Unknown, Family Home or Apartment 
into the function?


Is this correct?

 if ($_POST['DPRlocationdetails'] == Unknown)

Somebody once told me I had to do it this way?

 if (Unknown == $_POST['DPRlocationdetails'])

John

snip---

form action=foo.php id=DPRform method=postinput value=Update 
type=submit
input type=checkbox name=DPRlocationdetails[] value=Unknown ?php 
filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
input type=checkbox name=DPRlocationdetails[] value=Family Home 
?php filter_value($_POST['DPRlocationdetails'],Family Home); ? 
Family Home
input type=checkbox name=DPRlocationdetails[] value=Apartment 
?php filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment

/form

?php
function filter_value($tofilter,$tofind) {
foreach($tofilter as $value){
if ($value == $tofind) echo checked;
}
}
?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-19 Thread Jim Giner

On 2/19/2013 2:02 PM, John Taylor-Johnston wrote:


tamouse mailing lists wrote:

I hate arrays. :D

Here's a small snippet showing how it works, I hope:

foreach ($DPRpriority as $item = $value) {
   echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}


Question 1: when did we have to add [] to a input name to turn it into
an array?

input type=checkbox name=DPRlocationdetails[] value=Unknown

According to phpinfo() it still comes out as
$_POST['DPRlocationdetails'] without [].

Are the [] necessary?
--
Question 2:
I was looking at some code in the Manual, where someone used isset and
is_array.

How necessary is if(isset($_POST['DPRlocationdetails']))

and then to use: if(is_array($_POST['DPRlocationdetails']))

That seems like over kill?
--
Question 3:

My code works, perfectly. In this case, I decided to attack some
check-boxes first. The resulting function will work for select
multiple too..

Does anyone see me doing something wrong in my code below?

My questions are:

Is this the only way to pass Unknown, Family Home or Apartment
into the function?

Is this correct?

 if ($_POST['DPRlocationdetails'] == Unknown)

Somebody once told me I had to do it this way?

 if (Unknown == $_POST['DPRlocationdetails'])

John

snip---

form action=foo.php id=DPRform method=postinput value=Update
type=submit
input type=checkbox name=DPRlocationdetails[] value=Unknown ?php
filter_value($_POST['DPRlocationdetails'],Unknown); ? Unknown
input type=checkbox name=DPRlocationdetails[] value=Family Home
?php filter_value($_POST['DPRlocationdetails'],Family Home); ?
Family Home
input type=checkbox name=DPRlocationdetails[] value=Apartment
?php filter_value($_POST['DPRlocationdetails'],Apartment); ? Apartment
/form

?php
function filter_value($tofilter,$tofind) {
foreach($tofilter as $value){
 if ($value == $tofind) echo checked;
 }
}
?


The [] are necessary if there are going to be multiple occurrences of an 
input with the same name, hence the [] to allow your php script to 
extract all of the occurrences.


Using isset and is_array comes in handy to help you handle the incoming 
var properly.  If it IS set, you then have to check if there is only one 
value (hence a string) or if there are multiple values (an array).


#3 - no idea what you are asking.   

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] parsing select multiple=multiple

2013-02-18 Thread John Taylor-Johnston
I am capable with select name=DPRpriority. (I suppose I did it 
correctly? :p )
But I haven't the first clue how to parse a select multiple and 
multiply select name=DPRtype.

Would anyone give me a couple of clues please? :)
Thanks,
John

   Priority:
   select name=DPRpriority form=DPRform
 option value=1 ?php if ($_POST[DPRpriority] == 1) 
{echo selected;} ?1/option
 option value=2 ?php if ($_POST[DPRpriority] == 2) 
{echo selected;} ?2/option
 option value=3 ?php if ($_POST[DPRpriority] == 3) 
{echo selected;} ?3/option

 option value=4 ?php
 if (empty($_POST[DPRpriority])) {echo selected;}
 if ($_POST[DPRpriority] == 4) {echo selected;} 
?4/option

   /select


   select multiple=multiple name=DPRtype form=DPRform
 option value=1. Crimes Against Persons1. Crimes 
Against Persons/option

 option value=2. Disturbances2. Disturbances/option
 option value=3. Assistance / Medical3. Assistance / 
Medical/option
 option value=4. Crimes Against Property4. Crimes 
Against Property/option
 option value=5. Accidents / Traffic Problems5. 
Accidents / Traffic Problems/option
 option value=6. Suspicious Circumstances6. Suspicious 
Circumstances/option
 option value=7. Morality / Drugs7. Morality / 
Drugs/option
 option value=8. Miscellaneous Service8. Miscellaneous 
Service/option

 option value=9. Alarms9. Alarms/option
   /select


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread tamouse mailing lists
On Mon, Feb 18, 2013 at 6:54 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 I am capable with select name=DPRpriority. (I suppose I did it
 correctly? :p )
 But I haven't the first clue how to parse a select multiple and multiply
 select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

Priority:
select name=DPRpriority form=DPRform
  option value=1 ?php if ($_POST[DPRpriority] == 1) {echo
 selected;} ?1/option
  option value=2 ?php if ($_POST[DPRpriority] == 2) {echo
 selected;} ?2/option
  option value=3 ?php if ($_POST[DPRpriority] == 3) {echo
 selected;} ?3/option
  option value=4 ?php
  if (empty($_POST[DPRpriority])) {echo selected;}
  if ($_POST[DPRpriority] == 4) {echo selected;}
 ?4/option
/select


select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Do test this, but I think all that's required is you make the name an array:

select name=DPRpriority[] form=DPRform

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread John Taylor-Johnston



 select multiple=multiple name=DPRtype form=DPRform
 option value=1. Crimes Against Persons1. Crimes Against
Persons/option
 option value=2. Disturbances2. Disturbances/option
 option value=3. Assistance / Medical3. Assistance /
Medical/option
 option value=4. Crimes Against Property4. Crimes Against
Property/option
 option value=5. Accidents / Traffic Problems5. Accidents /
Traffic Problems/option
 option value=6. Suspicious Circumstances6. Suspicious
Circumstances/option
 option value=7. Morality / Drugs7. Morality /
Drugs/option
 option value=8. Miscellaneous Service8. Miscellaneous
Service/option
 option value=9. Alarms9. Alarms/option
   /select





Do test this, but I think all that's required is you make the name an array:

select name=DPRpriority[] form=DPRform
  

Something like this?

if $DPRpriority[0] == 7. Morality / Drugs { echo selected; }

I hate arrays. :D

http://php.net/manual/en/language.types.array.php

?php
$DPRpriority[]  = array(
   1= a,
   1  = b,
   1.5  = c,
   true = d,
);
var_dump($array);
?



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread David Robley
tamouse mailing lists wrote:

 On Mon, Feb 18, 2013 at 6:54 PM, John Taylor-Johnston
 john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 I am capable with select name=DPRpriority. (I suppose I did it
 correctly? :p )
 But I haven't the first clue how to parse a select multiple and
 multiply select name=DPRtype.
 Would anyone give me a couple of clues please? :)
 Thanks,
 John

Priority:
select name=DPRpriority form=DPRform
  option value=1 ?php if ($_POST[DPRpriority] == 1)
  {echo
 selected;} ?1/option
  option value=2 ?php if ($_POST[DPRpriority] == 2)
  {echo
 selected;} ?2/option
  option value=3 ?php if ($_POST[DPRpriority] == 3)
  {echo
 selected;} ?3/option
  option value=4 ?php
  if (empty($_POST[DPRpriority])) {echo selected;}
  if ($_POST[DPRpriority] == 4) {echo selected;}
 ?4/option
/select


select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents
  /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 
 Do test this, but I think all that's required is you make the name an
 array:
 
 select name=DPRpriority[] form=DPRform

More info at http://www.php.net/manual/en/language.variables.external.php 
(search for multiple) and 
http://www.php.net/manual/en/faq.html.php#faq.html.select-multiple

-- 
Cheers
David Robley

Know what I hate? I hate rhetorical questions!


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] parsing select multiple=multiple

2013-02-18 Thread tamouse mailing lists
On Mon, Feb 18, 2013 at 7:28 PM, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:

  select multiple=multiple name=DPRtype form=DPRform
  option value=1. Crimes Against Persons1. Crimes Against
 Persons/option
  option value=2. Disturbances2. Disturbances/option
  option value=3. Assistance / Medical3. Assistance /
 Medical/option
  option value=4. Crimes Against Property4. Crimes Against
 Property/option
  option value=5. Accidents / Traffic Problems5. Accidents
 /
 Traffic Problems/option
  option value=6. Suspicious Circumstances6. Suspicious
 Circumstances/option
  option value=7. Morality / Drugs7. Morality /
 Drugs/option
  option value=8. Miscellaneous Service8. Miscellaneous
 Service/option
  option value=9. Alarms9. Alarms/option
/select





 Do test this, but I think all that's required is you make the name an
 array:

 select name=DPRpriority[] form=DPRform


 Something like this?

 if $DPRpriority[0] == 7. Morality / Drugs { echo selected; }

 I hate arrays. :D

 http://php.net/manual/en/language.types.array.php

 ?php
 $DPRpriority[]  = array(
1= a,
1  = b,
1.5  = c,
true = d,
 );
 var_dump($array);
 ?


Not exactly that -- I think I goofed up your variable names.
$DPRpriority is the set of values that can be selected, and DPRType
are the values returned from the form.

Here's a small snippet showing how it works, I hope:

?php

// Initial value for demo
$DPRpriority = array(array('name' = Crimes Against Persons,
'selected' = false),
 array('name' = Disturbances, 'selected' = false),
 array('name' = Assistance / Medical, 'selected' = 
false),
 array('name' = Crimes Against Property, 'selected' = 
false),
 array('name' = Accidents / Traffic Problems, 'selected' 
= false),
 array('name' = Suspicious Circumstances, 'selected' = 
false),
 array('name' = Morality / Drugs, 'selected' = false),
 array('name' = Miscellaneous Service, 'selected' = 
false),
 array('name' =Alarms, 'selected' = false));

echo h1Initial value of DPRpriority:/h1ul\n;
foreach ($DPRpriority as $item = $value) {
  echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
}
echo /ul\n;

if (count($_POST)  0) {
  // something was posted:
  echo h1\$_POST:/h1precode\n;
  var_dump($_POST);
  echo /code/pre\n;

  echo h2Items selected:/h2ul\n;
  foreach ($_POST['DPRType'] as $item) {
$DPRpriority[$item]['selected'] = true;
echo li.$item.: .$DPRpriority[$item]['name']./li\n;
  }
  echo /ul\n;

  echo h1Final value of DPRpriority:/h1ul\n;
  foreach ($DPRpriority as $item = $value) {
echo li .$item.: .$value['name']. selected:
.$value['selected']. /li\n;
  }
  echo /ul\n;
}

?

form method=post

select name=DPRType[] id=DPRType[] multiple onchange=
size=?php echo count($DPRpriority) ?
  ?php foreach ($DPRpriority as $index = $value) { ?
option value=?php echo $index; ??php if ($value['selected'])
{echo ' selected=selected';} ??php echo
$value['name'];?/option
 ?php } ?
/select

input type=submit name=submit value=submit /

/form


(gist link: https://gist.github.com/tamouse/4982630 )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php