Re: [PHP] if (empty versus if (isset

2013-02-20 Thread ma...@behnke.biz
isset checks if something is defined or if an array has a key with a value other
than null

read:
http://www.php.net/manual/en/function.isset.php#refsect1-function.isset-returnvalues

empty check isset PLUS if the value is not null, false, 0 and wahtever php
thinks is empty

read:
http://www.php.net/manual/en/function.empty.php#refsect1-function.empty-returnvalues

You should also checkout array_key_exists

read: http://www.php.net/manual/en/function.array-key-exists.php

> John Taylor-Johnston  hat am 20.
> Februar 2013 um 03:29 geschrieben:
>
>
> What is the difference between?
>
> if (empty... http://www.php.net/manual/en/function.empty.php "Determine
> whether a variable is empty"
> and
> if (isset... http://php.net/manual/en/function.isset.php "Determine if a
> variable is set and is not *|NULL|*"
>
> I have an .
>
> If it is not checked, it is NOT empty, because it has a value, right?
> But it is NOT set, right?
>
> Is this empty, because it's value is ""?
>
> 
>
> Just trying to understand ... :)

--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

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



Re: [PHP] phpinfo()

2013-02-20 Thread Design in Motion Webdesign





John Taylor-Johnston  wrote:


I cannot find button2 in phpinfo() when I click it. I was hoping to
find
a $_POST["button2"] value.
What am I doing wrong?



I really wanted to use a button to pass a different condition than a



Use a different value or name on the  button. Don't 
use JavaScript to trigger the form like that. Its not necessary and will 
bite you in the ass if ypu get a visitor who browses without JavaScript, 
which can include security aware users, blind users, etc

Thanks,
Ash
http://www.ashleysheridan.co.uk

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



Try $_POST['button2']

Best regards.
Steven


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



[PHP] Re: if (empty versus if (isset

2013-02-20 Thread Jim Giner
Basically it tells a savvy programmer whether or not his logic has 
caused the var in question to "exist".  Many times it is important 
simply to know that, not what the var contains, which can lead to an 
error in processing.


The isset() will tell you that "yes, I have this variable", letting you 
then correctly interpret the contents.  If a $_POST var is not set 
(meaning the user made no input to it), the use of empty() will insist 
on telling you that the var is empty even tho it really was not provided 
by the user (assuming that you don't get an error msg for having an 
invalid index in the POST array).


They seem to be needlessly redundant, but in fact do provide knowledge 
for those seeking it.


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



Re: [PHP] Re: if (empty versus if (isset

2013-02-20 Thread ma...@behnke.biz


> Jim Giner  hat am 20. Februar 2013 um 15:10
> geschrieben:
>
>
> Basically it tells a savvy programmer whether or not his logic has
> caused the var in question to "exist".  Many times it is important
> simply to know that, not what the var contains, which can lead to an
> error in processing.
>
> The isset() will tell you that "yes, I have this variable", letting you
> then correctly interpret the contents.  If a $_POST var is not set
> (meaning the user made no input to it), the use of empty() will insist
> on telling you that the var is empty even tho it really was not provided
> by the user (assuming that you don't get an error msg for having an
> invalid index in the POST array).

keep in mind that isset returns false if the variable exists, but has a value of
null. The same applies to existing array keys with value null.

>
> They seem to be needlessly redundant, but in fact do provide knowledge
> for those seeking it.

No, they are not as I wrote in my last message

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

--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

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



Re: [PHP] if (empty versus if (isset

2013-02-20 Thread Tedd Sperling
On Feb 20, 2013, at 9:10 AM, Jim Giner  wrote:

> Basically it tells a savvy programmer whether or not his logic has caused the 
> var in question to "exist".  Many times it is important simply to know that, 
> not what the var contains, which can lead to an error in processing.
> 
> The isset() will tell you that "yes, I have this variable", letting you then 
> correctly interpret the contents.  If a $_POST var is not set (meaning the 
> user made no input to it), the use of empty() will insist on telling you that 
> the var is empty even tho it really was not provided by the user (assuming 
> that you don't get an error msg for having an invalid index in the POST 
> array).
> 
> They seem to be needlessly redundant, but in fact do provide knowledge for 
> those seeking it.
> 

That's one of the reason why I recommend using a Ternary Operator to check the 
POST array, such as:

$submit = isset($_POST['submit']) ? $_POST['submit'] : null;

That way, you never encounter an error looking for something that is not there.

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] phpinfo()

2013-02-20 Thread Tedd Sperling
On Feb 19, 2013, at 7:57 PM, John Taylor-Johnston 
 wrote:

> I cannot find button2 in phpinfo() when I click it. I was hoping to find a 
> $_POST["button2"] value.
> What am I doing wrong?
> 
>  onclick="formSubmit()">
> 
> I really wanted to use a button to pass a different condition than a  type="submit">

Lot's of different ways to pass values via forms.

Try using :



Then check the button2 value via a:

$button2 = isset($_POST['button2']) ? $_POST['button2'] : null;

That's one way -- there are many more.

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 Tedd Sperling
On Feb 18, 2013, at 7:54 PM, John Taylor-Johnston 
 wrote:

> I am capable with . (I suppose I did it correctly? 
> :p )
> But I haven't the first clue how to parse a  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 
 wrote:


I am capable with . (I suppose I did it correctly? 
:p )
But I haven't the first clue how to parse a  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



[PHP] stripped \n

2013-02-20 Thread John Taylor-Johnston

Hi,
I have a  when submitted creates a new form with the textarea 
data in a hidden field:




But when this new form gets resubmitted, the \n get stripped?



I don't get it.

There is nothing in my code that is stripping the \n?

value="">


Do I need to put it in another textarea and declare it hidden?


[PHP] Re: stripped \n

2013-02-20 Thread Jim Giner

On 2/20/2013 1:16 PM, John Taylor-Johnston wrote:

Hi,
I have a  when submitted creates a new form with the textarea
data in a hidden field:



But when this new form gets resubmitted, the \n get stripped?



I don't get it.

There is nothing in my code that is stripping the \n?

">

Do I need to put it in another textarea and declare it hidden?


Let me understand this logic.
You have a form that gathers some text from a field and then you submit 
that form to a script that wants to put it back out in a hidden field on 
a new form?  Is that it in a nutshell?



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



Re: [PHP] stripped \n

2013-02-20 Thread Matijn Woudt
On Wed, Feb 20, 2013 at 7:16 PM, John Taylor-Johnston <
john.taylor-johns...@cegepsherbrooke.qc.ca> wrote:

> Hi,
> I have a  when submitted creates a new form with the textarea
> data in a hidden field:
>
> 
>
> But when this new form gets resubmitted, the \n get stripped?
>
> 
>
> I don't get it.
>
> There is nothing in my code that is stripping the \n?
>
> ">
>
> Do I need to put it in another textarea and declare it hidden?
>

An input with type=text is used for single lines, so yes, newlines get
stripped.
Either use a textarea with style="display: none", or store the data in a
session instead.

- Matijn


Re: [PHP] stripped \n

2013-02-20 Thread Daniel Brown
On Wed, Feb 20, 2013 at 1:32 PM, Matijn Woudt  wrote:
>
> An input with type=text is used for single lines, so yes, newlines get
> stripped.
> Either use a textarea with style="display: none", or store the data in a
> session instead.

Or at least .

-- 

Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] stripped \n

2013-02-20 Thread Jim Giner

On 2/20/2013 1:32 PM, Matijn Woudt wrote:

On Wed, Feb 20, 2013 at 7:16 PM, John Taylor-Johnston <
john.taylor-johns...@cegepsherbrooke.qc.ca> wrote:


Hi,
I have a  when submitted creates a new form with the textarea
data in a hidden field:



But when this new form gets resubmitted, the \n get stripped?



I don't get it.

There is nothing in my code that is stripping the \n?

">

Do I need to put it in another textarea and declare it hidden?



An input with type=text is used for single lines, so yes, newlines get
stripped.
Either use a textarea with style="display: none", or store the data in a
session instead.

- Matijn

Actually - an  may be intended for single lines, but my 
test shows that it does not drop the \ all by itself.


And actually, the poster's question is very difficult to understand, 
simply because I do believe he doesn't know anything about html or php. 
 Probably building something from examples he has seen.


1 - he doesn't show a  tag in his examples
2 - his sample of his code is such a small fragment we can't tell WHAT 
he is doing.


Most likely the problem is his use of stripslashes in that last code 
line he provided.  I wonder if he knows what that does?


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



Re: [PHP] stripped \n

2013-02-20 Thread Ashley Sheridan
On Wed, 2013-02-20 at 13:47 -0500, Jim Giner wrote:

> On 2/20/2013 1:32 PM, Matijn Woudt wrote:
> > On Wed, Feb 20, 2013 at 7:16 PM, John Taylor-Johnston <
> > john.taylor-johns...@cegepsherbrooke.qc.ca> wrote:
> >
> >> Hi,
> >> I have a  when submitted creates a new form with the textarea
> >> data in a hidden field:
> >>
> >> 
> >>
> >> But when this new form gets resubmitted, the \n get stripped?
> >>
> >> 
> >>
> >> I don't get it.
> >>
> >> There is nothing in my code that is stripping the \n?
> >>
> >> ">
> >>
> >> Do I need to put it in another textarea and declare it hidden?
> >>
> >
> > An input with type=text is used for single lines, so yes, newlines get
> > stripped.
> > Either use a textarea with style="display: none", or store the data in a
> > session instead.
> >
> > - Matijn
> >
> Actually - an  may be intended for single lines, but my 
> test shows that it does not drop the \ all by itself.
> 
> And actually, the poster's question is very difficult to understand, 
> simply because I do believe he doesn't know anything about html or php. 
>   Probably building something from examples he has seen.
> 
> 1 - he doesn't show a  tag in his examples
> 2 - his sample of his code is such a small fragment we can't tell WHAT 
> he is doing.
> 
> Most likely the problem is his use of stripslashes in that last code 
> line he provided.  I wonder if he knows what that does?
> 


Also, with the example:




There is no hidden attribute for input elements, and no form attribute
either. If there's a need to stuff elements with extra attributes then
it's best to use data- attributes.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] phpinfo()

2013-02-20 Thread John Taylor-Johnston



Design in Motion Webdesign wrote:





John Taylor-Johnston  wrote:


I cannot find button2 in phpinfo() when I click it. I was hoping to
find
a $_POST["button2"] value.
What am I doing wrong?



I really wanted to use a button to pass a different condition than a



Use a different value or name on the  button. 
Don't use JavaScript to trigger the form like that. Its not necessary 
and will bite you in the ass if ypu get a visitor who browses without 
JavaScript, which can include security aware users, blind users, etc

Thanks,
Ash
http://www.ashleysheridan.co.uk

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



Try $_POST['button2']

Best regards.
Steven



$_POST['button2'] does not exist. I'm using radio to get aorund it for 
now. A button would have been cleaner.



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



Re: [PHP] phpinfo()

2013-02-20 Thread Ashley Sheridan
On Wed, 2013-02-20 at 14:23 -0500, John Taylor-Johnston wrote:

> 
> Design in Motion Webdesign wrote:
> >
> >>
> >>
> >> John Taylor-Johnston  wrote:
> >>
> >>> I cannot find button2 in phpinfo() when I click it. I was hoping to
> >>> find
> >>> a $_POST["button2"] value.
> >>> What am I doing wrong?
> >>>
> >>>  >>> onclick="formSubmit()">
> >>>
> >>> I really wanted to use a button to pass a different condition than a
> >>> 
> >>
> >> Use a different value or name on the  button. 
> >> Don't use JavaScript to trigger the form like that. Its not necessary 
> >> and will bite you in the ass if ypu get a visitor who browses without 
> >> JavaScript, which can include security aware users, blind users, etc
> >> Thanks,
> >> Ash
> >> http://www.ashleysheridan.co.uk
> >>
> >> -- 
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
> > Try $_POST['button2']
> >
> > Best regards.
> > Steven
> >
> 
> $_POST['button2'] does not exist. I'm using radio to get aorund it for 
> now. A button would have been cleaner.
> 
> 




Not sure what you have against submit buttons, because this will do what
you want and you don't need to be doing whatever it is you're doing with
radio buttons?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] phpinfo()

2013-02-20 Thread Stuart Dallas
On 20 Feb 2013, at 19:23, John Taylor-Johnston 
 wrote:

> 
> 
> Design in Motion Webdesign wrote:
>> 
>>> 
>>> 
>>> John Taylor-Johnston  wrote:
>>> 
 I cannot find button2 in phpinfo() when I click it. I was hoping to
 find
 a $_POST["button2"] value.
 What am I doing wrong?
 
 >>> onclick="formSubmit()">
 
 I really wanted to use a button to pass a different condition than a
 
>>> 
>>> Use a different value or name on the  button. Don't 
>>> use JavaScript to trigger the form like that. Its not necessary and will 
>>> bite you in the ass if ypu get a visitor who browses without JavaScript, 
>>> which can include security aware users, blind users, etc
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>> 
>>> -- 
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>> 
>> 
>> Try $_POST['button2']
>> 
>> Best regards.
>> Steven
>> 
> 
> $_POST['button2'] does not exist. I'm using radio to get aorund it for now. A 
> button would have been cleaner.

You were given the answer, did you not try it?

Starting with the code in your original post:

1) Change the type to submit.
2) Remove the onclick.
3) Job done!

-Stuart

-- 
Sent from my leaf blower
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stripped \n

2013-02-20 Thread Jim Lucas

On 02/20/2013 10:16 AM, John Taylor-Johnston wrote:

Hi,
I have a  when submitted creates a new form with the textarea
data in a hidden field:



But when this new form gets resubmitted, the \n get stripped?



I don't get it.

There is nothing in my code that is stripping the \n?

">

Do I need to put it in another textarea and declare it hidden?



Here is a quote:

If the element is mutable, its value should be editable by the user. 
User agents must not allow users to insert "LF" (U+000A) or "CR" 
(U+000D) characters into the element's value.



I found it on this page:

http://www.w3.org/TR/html5/forms.html#text-%28type=text%29-state-and-search-state-%28type=search%29

Does that explain why your example doesn't work?

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

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



Re: [PHP] phpinfo()

2013-02-20 Thread Tedd Sperling
On Feb 20, 2013, at 2:31 PM, Stuart Dallas  wrote:
> You were given the answer, did you not try it?
> 
> Starting with the code in your original post:
> 
> 1) Change the type to submit.
> 2) Remove the onclick.
> 3) Job done!
> 
> -Stuart


Sometimes you just can't help.


> Sent from my leaf blower  :-)

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] phpinfo()

2013-02-20 Thread tamouse mailing lists
On Wed, Feb 20, 2013 at 1:31 PM, Stuart Dallas  wrote:
> -Stuart
>
> --
> Sent from my leaf blower
> --

Did you get the 4G model, or is this just the WiFi version?

-- 
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
 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 " ".$item.": ".$value['name']." selected:
>> ".$value['selected']." \n";
>> }
>>
> Question 1: when did we have to add [] to a  name to turn it into an
> array?
>
> 
>
> 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  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---
>
>  type="submit">
>  filter_value($_POST['DPRlocationdetails'],"Unknown"); ?>> Unknown
>  filter_value($_POST['DPRlocationdetails'],"Family Home"); ?>> Family Home
>  filter_value($_POST['DPRlocationdetails'],"Apartment"); ?>> Apartment
> 
>
>  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