Re: [PHP] Re: Best way to test for form submission?

2009-08-29 Thread Tom Worster
On 8/29/09 9:29 AM, "tedd"  wrote:

> At 1:18 AM -0700 8/29/09, Warren Vail wrote:
>> To test a form I usually send the form contents to a php file that contains
>> the following;
>> 
>> foreach($_POST as $nm => $val) echo "_POST[".$nm."] [".$val."]";
>> foreach($_GET as $nm => $val) echo "_GET[".$nm."] [".$val."]";
>> 
>> Checkboxes and radio buttons only send their value if the control is
>> "checked".
>> 
> 
> That's correct, here's the way I solve both types:
> 
> http://php1.net/b/form-radio
> http://php1.net/b/form-radio1
> http://php1.net/b/form-checkbox/
> http://php1.net/b/form-checkbox1/

warren's test script above doesn't work so well with tedd's scheme for
naming radios & checkboxs. tedd uses name="option[]" in the markup so in
warren's script, when $nm is 'option', $val will be an array so it won't
convert to a string in ".$val.".



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



Re: [PHP] Re: Best way to test for form submission?

2009-08-29 Thread Robert Cummings

Warren Vail wrote:

To test a form I usually send the form contents to a php file that contains
the following;

foreach($_POST as $nm => $val) echo "_POST[".$nm."] [".$val."]";
foreach($_GET as $nm => $val) echo "_GET[".$nm."] [".$val."]";

Checkboxes and radio buttons only send their value if the control is
"checked".

You can have multiple submit buttons (type="submit") on a form, but you
should assign them different name parameters to recognize which one is
clicked (any one of them will cause the form to be submitted, but the only
one that will establish a $_POST entry named "submit" is the submit control
that is named "submit" (name="submit").


I would suggest NOT naming any field submit. There will come a time when 
you will want to do form.submit() in JavaScript and you will find it 
broken in one of the browsers. I'm not sure which, but one of them 
breaks if you have named a field "submit". As a result I always use 
"continue" instead :)


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



RE: [PHP] Re: Best way to test for form submission?

2009-08-29 Thread tedd

At 1:18 AM -0700 8/29/09, Warren Vail wrote:

To test a form I usually send the form contents to a php file that contains
the following;

foreach($_POST as $nm => $val) echo "_POST[".$nm."] [".$val."]";
foreach($_GET as $nm => $val) echo "_GET[".$nm."] [".$val."]";

Checkboxes and radio buttons only send their value if the control is
"checked".



That's correct, here's the way I solve both types:

http://php1.net/b/form-radio
http://php1.net/b/form-radio1
http://php1.net/b/form-checkbox/
http://php1.net/b/form-checkbox1/

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] Re: Best way to test for form submission?

2009-08-29 Thread tedd

At 5:51 PM +0100 8/28/09, Ashley Sheridan wrote:

 I usually just
tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
benefit of being able to work with both arrays (as well as $_SESSION and
$_COOKIE) without any drawbacks.

Thanks,
Ash


Ash:

Drawbacks are funny things.

Not knowing where my data originated ($_GET, $_POST, or $_COOKIE) and 
having the possibility of what I was expecting overridden in a 
$_REQUEST is what I would call a drawback.


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] Re: Best way to test for form submission?

2009-08-29 Thread tedd

At 5:33 PM +0100 8/28/09, Ashley Sheridan wrote:

On Fri, 2009-08-28 at 12:28 -0400, tedd wrote:
 > Ash:


 What catches me every once in a while is using variable names that
 are the same as $_SESSION indexes, such as:

 $session_name =  $_SESSION['session_name'];

 Believe it or not, that does NOT always work! Sometimes I have to do this --

 $my_session_name =  $_SESSION['session_name'];

 -- to get around the problem.

 I have experienced this error more than once -- it's strange.

 Cheers,

 tedd


Does that happen even with register globals off?


Yes. it happens with register globals set to off

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] Re: Best way to test for form submission?

2009-08-29 Thread Warren Vail
To test a form I usually send the form contents to a php file that contains
the following;

foreach($_POST as $nm => $val) echo "_POST[".$nm."] [".$val."]";
foreach($_GET as $nm => $val) echo "_GET[".$nm."] [".$val."]";

Checkboxes and radio buttons only send their value if the control is
"checked".

You can have multiple submit buttons (type="submit") on a form, but you
should assign them different name parameters to recognize which one is
clicked (any one of them will cause the form to be submitted, but the only
one that will establish a $_POST entry named "submit" is the submit control
that is named "submit" (name="submit"). 

Pressing enter is not sensed by most controls.
Most browsers will look at the field the cursor is positioned on when enter
is pressed, and if it is not one of the controls that response to an enter,
it scans the DOM (list of controls), and will apply the enter to the first
control that responds to an enter, most common is the type="submit" control.


If a select control is between the text box and the submit button (in the
DOM list) the current entry for the select list will be selected and the
form will not be submitted unless the list includes a
onChange="this.form.submit(); " javascript entry.

Be careful designing forms that are dependent on some of these behaviors,
like positioning a submit button to the right of a text box to intentionally
receive the "enter", because different browsers will probably behave
differently.

Hope this helps a bit.

Warren Vail
Vail Systems Technology

-Original Message-----
From: Keith [mailto:survivor_...@hotmail.com] 
Sent: Friday, August 28, 2009 9:51 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Re: Best way to test for form submission?

I've encountered issue with checking $_POST['submit']
if(isset($_POST['submit'])) {}

If the form consists of checkbox/radio and text field, some of my forms can 
be submitted by just press [ENTER] at the end of one of the text field. In 
this case, the $_POST['submit'] is set even the  submit button was not 
clicked.
However, in some of my forms, $_POST['submit'] will not be set if I submit 
the form by pressing [ENTER] in one of the text field.
So, if the later case happen, I need to remind the user to explicitly click 
the [Submit] button.
I don't know why or in what condition that pressing [ENTER] will not submit 
the whole form include the $_POST['submit'].

Keith


"Ashley Sheridan"  wrote in message 
news:1251467419.27899.106.ca...@localhost...
> On Thu, 2009-08-27 at 23:21 -0400, Adam Jimerson wrote:
>> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>> > This question might give away the fact that I am a php noob, but I am
>> > looking for the best way to test for form submission in PHP.  I know in
>> > Perl this can be done with
>> >
>> > if (param)
>> >
>> > but I don't know if that will work with PHP.  I have read the Learning
>> > PHP 5 book and the only thing that was mentioned in the book was the 
>> > use
>> > of something like this
>> >
>> > print "Hello ".$_POST['username']."";
>>
>> Sorry copied and pasted the wrong line (long day)
>>
>> if (array_key_exists('username',$_POST))
>> >
>> > I'm sure that this is not the best/recommended way to do this but I'm
>> > hoping someone here will point me in the right direction.
>>
>>
>
> The best way I've found is to do something like this:
>
> if(isset($_POST['submit']))
> {}
>
> Note that in-place of submit you can put the name of any form element. I
> chose submit here, because every form should have a submit button. Note
> also that this will only work if you have given your submit button a
> name:
>
> 
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
> 

-- 
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] Re: Best way to test for form submission?

2009-08-29 Thread Nisse Engström
On Sat, 29 Aug 2009 12:50:41 +0800, "Keith" wrote:

> I don't know why or in what condition that pressing [ENTER] will not submit 
> the whole form include the $_POST['submit'].





/Nisse

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread J DeBord
I've heard stories like this before, but never encountered it myself.

I forgot to mention that it is a good idea to give your submit buttons a
"value" attribute. Regardless of how the form is submitted, you should then
have a value for ['submit'].

Reminding the user that they must do anything other than the simplest things
is usually not a good approach. There will inevitably be users who do not
see/follow your reminder and use the enter button. Give the submit button a
value.


On Sat, Aug 29, 2009 at 6:50 AM, Keith  wrote:

> I've encountered issue with checking $_POST['submit']
>   if(isset($_POST['submit'])) {}
>
> If the form consists of checkbox/radio and text field, some of my forms can
> be submitted by just press [ENTER] at the end of one of the text field. In
> this case, the $_POST['submit'] is set even the  submit button was not
> clicked.
> However, in some of my forms, $_POST['submit'] will not be set if I submit
> the form by pressing [ENTER] in one of the text field.
> So, if the later case happen, I need to remind the user to explicitly click
> the [Submit] button.
> I don't know why or in what condition that pressing [ENTER] will not submit
> the whole form include the $_POST['submit'].
>
> Keith
>
>
> "Ashley Sheridan"  wrote in message
> news:1251467419.27899.106.ca...@localhost...
>
>  On Thu, 2009-08-27 at 23:21 -0400, Adam Jimerson wrote:
>>
>>> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>>> > This question might give away the fact that I am a php noob, but I am
>>> > looking for the best way to test for form submission in PHP.  I know in
>>> > Perl this can be done with
>>> >
>>> > if (param)
>>> >
>>> > but I don't know if that will work with PHP.  I have read the Learning
>>> > PHP 5 book and the only thing that was mentioned in the book was the >
>>> use
>>> > of something like this
>>> >
>>> > print "Hello ".$_POST['username']."";
>>>
>>> Sorry copied and pasted the wrong line (long day)
>>>
>>> if (array_key_exists('username',$_POST))
>>> >
>>> > I'm sure that this is not the best/recommended way to do this but I'm
>>> > hoping someone here will point me in the right direction.
>>>
>>>
>>>
>> The best way I've found is to do something like this:
>>
>> if(isset($_POST['submit']))
>> {}
>>
>> Note that in-place of submit you can put the name of any form element. I
>> chose submit here, because every form should have a submit button. Note
>> also that this will only work if you have given your submit button a
>> name:
>>
>> 
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Keith

I've encountered issue with checking $_POST['submit']
   if(isset($_POST['submit'])) {}

If the form consists of checkbox/radio and text field, some of my forms can 
be submitted by just press [ENTER] at the end of one of the text field. In 
this case, the $_POST['submit'] is set even the  submit button was not 
clicked.
However, in some of my forms, $_POST['submit'] will not be set if I submit 
the form by pressing [ENTER] in one of the text field.
So, if the later case happen, I need to remind the user to explicitly click 
the [Submit] button.
I don't know why or in what condition that pressing [ENTER] will not submit 
the whole form include the $_POST['submit'].


Keith


"Ashley Sheridan"  wrote in message 
news:1251467419.27899.106.ca...@localhost...

On Thu, 2009-08-27 at 23:21 -0400, Adam Jimerson wrote:

On 08/27/2009 11:09 PM, Adam Jimerson wrote:
> This question might give away the fact that I am a php noob, but I am
> looking for the best way to test for form submission in PHP.  I know in
> Perl this can be done with
>
> if (param)
>
> but I don't know if that will work with PHP.  I have read the Learning
> PHP 5 book and the only thing that was mentioned in the book was the 
> use

> of something like this
>
> print "Hello ".$_POST['username']."";

Sorry copied and pasted the wrong line (long day)

if (array_key_exists('username',$_POST))
>
> I'm sure that this is not the best/recommended way to do this but I'm
> hoping someone here will point me in the right direction.




The best way I've found is to do something like this:

if(isset($_POST['submit']))
{}

Note that in-place of submit you can put the name of any form element. I
chose submit here, because every form should have a submit button. Note
also that this will only work if you have given your submit button a
name:



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





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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread J DeBord
If you want to check that a *form* was submiited, you need to at minimum
check that one of the form elements exist in the post data, assuming the
method is post. The submit button is a good one to use. Just checking that
there *is* POST data isn't a great idea. Anyone can post anything. Checking
for a key named 'submit' in the POST array is no more difficult than any
other method. That being said anyone could POST a key value pair with the
key being 'submit'. So validate everything!

On Fri, Aug 28, 2009 at 7:29 PM, Martin Scotta wrote:

> On Fri, Aug 28, 2009 at 1:59 PM, Ben Dunlap  >wrote:
>
> > > Well, as far as I'm aware $_SERVER isn't reliable from server to
> server.
> > > That said, I've never had a problem using it.
> >
> > Thanks -- I just looked it up and the manual says: "There is no
> > guarantee that every web server will provide any of these; servers may
> > omit some, or provide others not listed here. That said, a large
> > number of these variables are accounted for in the » CGI 1.1
> > specification, so you should be able to expect those."
> >
> > So I guess it wouldn't make sense to rely on anything in $_SERVER if
> > you're building an app for widespread use; e.g., CodeIgniter, as
> > mentioned above.
> >
> > > tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
> > > benefit of being able to work with both arrays (as well as $_SESSION
> and
> > > $_COOKIE) without any drawbacks.
> >
> > For now I'm inclined against $_REQUEST, since it's not yet supported
> > by filter_input(). I think filter_input() is the bee's knees and I've
> > stopped touching $_POST or $_GET directly since I discovered it.
> >
> > Ben
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> When the request is PUT your $_SERVER['REQUEST_METHOD'] detection will
> fail,
> but the $_POST will be populated.
>
> I think the best way is by count( $_POST ) > 0 but this only applies for
> application/x-www-form-urlencoded forms.
> Other content-type will not populate the $_POST and therefore need to be
> validated by other method.
>
> PHP provides non-yet-standard HttpRequest class that can handle this
> perfectly
>
>
> --
> Martin Scotta
>


Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Martin Scotta
On Fri, Aug 28, 2009 at 1:59 PM, Ben Dunlap wrote:

> > Well, as far as I'm aware $_SERVER isn't reliable from server to server.
> > That said, I've never had a problem using it.
>
> Thanks -- I just looked it up and the manual says: "There is no
> guarantee that every web server will provide any of these; servers may
> omit some, or provide others not listed here. That said, a large
> number of these variables are accounted for in the » CGI 1.1
> specification, so you should be able to expect those."
>
> So I guess it wouldn't make sense to rely on anything in $_SERVER if
> you're building an app for widespread use; e.g., CodeIgniter, as
> mentioned above.
>
> > tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
> > benefit of being able to work with both arrays (as well as $_SESSION and
> > $_COOKIE) without any drawbacks.
>
> For now I'm inclined against $_REQUEST, since it's not yet supported
> by filter_input(). I think filter_input() is the bee's knees and I've
> stopped touching $_POST or $_GET directly since I discovered it.
>
> Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
When the request is PUT your $_SERVER['REQUEST_METHOD'] detection will fail,
but the $_POST will be populated.

I think the best way is by count( $_POST ) > 0 but this only applies for
application/x-www-form-urlencoded forms.
Other content-type will not populate the $_POST and therefore need to be
validated by other method.

PHP provides non-yet-standard HttpRequest class that can handle this
perfectly


-- 
Martin Scotta


Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Sat, 2009-08-29 at 01:09 +0800, Eric wrote:
> - Original Message - 
> From: "Ashley Sheridan" 
> To: "Ben Dunlap" 
> Cc: 
> Sent: Saturday, August 29, 2009 12:51 AM
> Subject: Re: [PHP] Re: Best way to test for form submission?
> 
> 
> > On Fri, 2009-08-28 at 09:33 -0700, Ben Dunlap wrote:
> >> I was surprised when no one recommended this:
> >> 
> >>if ($_SERVER['REQUEST_METHOD'] == 'POST')
> >> 
> >> So now I'm wondering if there's a pitfall to this method that I'm not
> >> aware of...
> >> 
> >> Thanks,
> >> 
> >> Ben
> >> 
> > 
> > Well, as far as I'm aware $_SERVER isn't reliable from server to server.
> > That said, I've never had a problem using it.
> > 
> > I probably wouldn't use this however, as it does only check for the
> > existence of POST data. Sometimes I'll trigger the same PHP script from
> > both POST and GET. For example, a search form would use POST in the
> > initial form, and then if it was paginated, the links forwards and
> > backwards through the results would be GET (like Google) I usually just
> > tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
> > benefit of being able to work with both arrays (as well as $_SESSION and
> > $_COOKIE) without any drawbacks.
> 
> 
> If only use the $_REQUEST global array. It may or may not be take a risk of 
> CSRF. Take a look this linke http://www.cgisecurity.com/csrf-faq.html
> 
> I read it a few days before.
> 
> Eric
> 
> > 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> > 
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> >
It's no less safe than just using $_POST (which the article itself
says). The sensible thing to do is mistrust ANY data coming from the
client machine, and always validate it before using it.

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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ben Dunlap
> Well, as far as I'm aware $_SERVER isn't reliable from server to server.
> That said, I've never had a problem using it.

Thanks -- I just looked it up and the manual says: "There is no
guarantee that every web server will provide any of these; servers may
omit some, or provide others not listed here. That said, a large
number of these variables are accounted for in the » CGI 1.1
specification, so you should be able to expect those."

So I guess it wouldn't make sense to rely on anything in $_SERVER if
you're building an app for widespread use; e.g., CodeIgniter, as
mentioned above.

> tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
> benefit of being able to work with both arrays (as well as $_SESSION and
> $_COOKIE) without any drawbacks.

For now I'm inclined against $_REQUEST, since it's not yet supported
by filter_input(). I think filter_input() is the bee's knees and I've
stopped touching $_POST or $_GET directly since I discovered it.

Ben

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 09:33 -0700, Ben Dunlap wrote:
> I was surprised when no one recommended this:
> 
>if ($_SERVER['REQUEST_METHOD'] == 'POST')
> 
> So now I'm wondering if there's a pitfall to this method that I'm not
> aware of...
> 
> Thanks,
> 
> Ben
> 

Well, as far as I'm aware $_SERVER isn't reliable from server to server.
That said, I've never had a problem using it.

I probably wouldn't use this however, as it does only check for the
existence of POST data. Sometimes I'll trigger the same PHP script from
both POST and GET. For example, a search form would use POST in the
initial form, and then if it was paginated, the links forwards and
backwards through the results would be GET (like Google) I usually just
tend to use the $_REQUEST array instead of $_POST or $_GET. You get the
benefit of being able to work with both arrays (as well as $_SESSION and
$_COOKIE) without any drawbacks.

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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ben Dunlap
I was surprised when no one recommended this:

   if ($_SERVER['REQUEST_METHOD'] == 'POST')

So now I'm wondering if there's a pitfall to this method that I'm not
aware of...

Thanks,

Ben

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 12:28 -0400, tedd wrote:
> At 4:49 PM +0100 8/28/09, Ashley Sheridan wrote:
> >
> >  >
> >I seem to always use the word! *smacks self on wrist*
> >
> >When I first came across it, it confused the hell out of me! Always
> >running into these kinds of Javascript bugs in IE, it has a much
> >narrower field of 'safe' variable names, probably because of all the
> >dithering about it's done in the past.
> >
> >Thanks,
> >Ash
> 
> Ash:
> 
> What catches me every once in a while is using variable names that 
> are the same as $_SESSION indexes, such as:
> 
> $session_name =  $_SESSION['session_name'];
> 
> Believe it or not, that does NOT always work! Sometimes I have to do this --
> 
> $my_session_name =  $_SESSION['session_name'];
> 
> -- to get around the problem.
> 
> I have experienced this error more than once -- it's strange.
> 
> Cheers,
> 
> tedd
> 
Does that happen even with register globals off?

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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread tedd

At 4:49 PM +0100 8/28/09, Ashley Sheridan wrote:


 >
I seem to always use the word! *smacks self on wrist*

When I first came across it, it confused the hell out of me! Always
running into these kinds of Javascript bugs in IE, it has a much
narrower field of 'safe' variable names, probably because of all the
dithering about it's done in the past.

Thanks,
Ash


Ash:

What catches me every once in a while is using variable names that 
are the same as $_SESSION indexes, such as:


   $session_name =  $_SESSION['session_name'];

Believe it or not, that does NOT always work! Sometimes I have to do this --

   $my_session_name =  $_SESSION['session_name'];

-- to get around the problem.

I have experienced this error more than once -- it's strange.

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] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 11:39 -0400, tedd wrote:
> At 4:32 PM +0100 8/28/09, Ashley Sheridan wrote:
> >
> >
> >I have noticed a bug with using a form element named action, which
> >funnily enough only effects IE. If you need to do anything to or based
> >on that action element in IE with Javascript, it has a lot of problems
> >differentiating the form element from the form action attribute, and
> >gets them a bit confused. It's similar to the IE name/id bug.
> >
> >Thanks,
> >Ash
> 
> Good catch.
> 
> I actually never use the word $action -- that's just a placeholder.
> 
> Cheers,
> 
> tedd
> 
> -- 
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 
I seem to always use the word! *smacks self on wrist*

When I first came across it, it confused the hell out of me! Always
running into these kinds of Javascript bugs in IE, it has a much
narrower field of 'safe' variable names, probably because of all the
dithering about it's done in the past.

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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread tedd

At 4:32 PM +0100 8/28/09, Ashley Sheridan wrote:



I have noticed a bug with using a form element named action, which
funnily enough only effects IE. If you need to do anything to or based
on that action element in IE with Javascript, it has a lot of problems
differentiating the form element from the form action attribute, and
gets them a bit confused. It's similar to the IE name/id bug.

Thanks,
Ash


Good catch.

I actually never use the word $action -- that's just a placeholder.

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] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 11:29 -0400, tedd wrote:
> At 3:10 PM +0100 8/28/09, Stuart wrote:
> >2009/8/28 Eric :
> >  > Here is another way
> >>
> >>  if (isset($_POST['username'])  && $_POST['username'] != '')
> >>  { ...
> >
> >If you use this method then you'll completely ignore a form submission
> >if they've forgotten to enter a username. Detection and validation are
> >two distinct steps and should be treated as such.
> >
> >-Stuart
> 
> 
> I usually treat forms this way:
> 
> $action = isset($_POST['action']) ? $_POST['action'] : null;
> 
> and then deal with $action.
> 
> Dealing with $action means that I might clean/scrub it for storage in 
> MySQL, or use it to determine a course of processing, or any number 
> of other things.
> 
> The point is to check IF a $_POST has occurred, without triggering an 
> error if it hasn't, and to deal with the outcome either way.
> 
> Cheers,
> 
> tedd
> 
> -- 
> ---
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 

I have noticed a bug with using a form element named action, which
funnily enough only effects IE. If you need to do anything to or based
on that action element in IE with Javascript, it has a lot of problems
differentiating the form element from the form action attribute, and
gets them a bit confused. It's similar to the IE name/id bug.

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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread tedd

At 3:10 PM +0100 8/28/09, Stuart wrote:

2009/8/28 Eric :
 > Here is another way


 if (isset($_POST['username'])  && $_POST['username'] != '')
 { ...


If you use this method then you'll completely ignore a form submission
if they've forgotten to enter a username. Detection and validation are
two distinct steps and should be treated as such.

-Stuart



I usually treat forms this way:

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

and then deal with $action.

Dealing with $action means that I might clean/scrub it for storage in 
MySQL, or use it to determine a course of processing, or any number 
of other things.


The point is to check IF a $_POST has occurred, without triggering an 
error if it hasn't, and to deal with the outcome either way.


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] Re: Best way to test for form submission?

2009-08-28 Thread Stuart
2009/8/28 Eric :
>
> - Original Message -
> From: "Stuart" 
> To: "Eric" 
> Cc: ; "Adam Jimerson" 
> Sent: Friday, August 28, 2009 10:10 PM
> Subject: Re: [PHP] Re: Best way to test for form submission?
>
>
> 2009/8/28 Eric :
>>
>> - Original Message -
>> From: "Adam Jimerson" 
>> To: 
>> Sent: Friday, August 28, 2009 11:21 AM
>> Subject: [PHP] Re: Best way to test for form submission?
>>
>>
>>> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>>>> This question might give away the fact that I am a php noob, but I am
>>>> looking for the best way to test for form submission in PHP. I know in
>>>> Perl this can be done with
>>>>
>>>> if (param)
>>>>
>>>> but I don't know if that will work with PHP. I have read the Learning
>>>> PHP 5 book and the only thing that was mentioned in the book was the use
>>>> of something like this
>>>>
>>>> print "Hello ".$_POST['username']."";
>>>
>>> Sorry copied and pasted the wrong line (long day)
>>>
>>> if (array_key_exists('username',$_POST))
>>
>> Here is another way
>>
>> if (isset($_POST['username']) && $_POST['username'] != '')
>> { ...
>
> If you use this method then you'll completely ignore a form submission
> if they've forgotten to enter a username. Detection and validation are
> two distinct steps and should be treated as such.
>
> Stuart
> thanks,
>
> how about this way
>
> $submit = isset($_POST['submit']) ? true : false;
> if ($submit)
>  { ...

Why the variable? It's unnecessary, as is the ?: operator - isset
returns a boolean.

if (isset($_POST['submit'])) will achieve the same result.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Paul M Foster
On Fri, Aug 28, 2009 at 02:53:56PM +0100, Stuart wrote:

> 2009/8/28 Adam Jimerson :
> > On 08/27/2009 11:09 PM, Adam Jimerson wrote:
> >> This question might give away the fact that I am a php noob, but I am
> >> looking for the best way to test for form submission in PHP.  I know in
> >> Perl this can be done with
> >>
> >> if (param)
> >>
> >> but I don't know if that will work with PHP.  I have read the Learning
> >> PHP 5 book and the only thing that was mentioned in the book was the use
> >> of something like this
> >>
> >> print "Hello ".$_POST['username']."";
> >
> > Sorry copied and pasted the wrong line (long day)
> >
> > if (array_key_exists('username',$_POST))
> >>
> >> I'm sure that this is not the best/recommended way to do this but I'm
> >> hoping someone here will point me in the right direction.
> 
> Two options...
> 
> 1) if (isset($_POST['username'])) // Specific to any given form
> 
> 2) if (count($_POST) > 0) // Just tests whether any data was POSTed

FWIW, the CodeIgniter framework uses this latter method internally.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Stuart
2009/8/28 Eric :
>
> - Original Message -
> From: "Adam Jimerson" 
> To: 
> Sent: Friday, August 28, 2009 11:21 AM
> Subject: [PHP] Re: Best way to test for form submission?
>
>
>> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>>> This question might give away the fact that I am a php noob, but I am
>>> looking for the best way to test for form submission in PHP.  I know in
>>> Perl this can be done with
>>>
>>> if (param)
>>>
>>> but I don't know if that will work with PHP.  I have read the Learning
>>> PHP 5 book and the only thing that was mentioned in the book was the use
>>> of something like this
>>>
>>> print "Hello ".$_POST['username']."";
>>
>> Sorry copied and pasted the wrong line (long day)
>>
>> if (array_key_exists('username',$_POST))
>
> Here is another way
>
> if (isset($_POST['username'])  && $_POST['username'] != '')
> { ...

If you use this method then you'll completely ignore a form submission
if they've forgotten to enter a username. Detection and validation are
two distinct steps and should be treated as such.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Martin Scotta
what about a simple

if( count( $_POST ))

All you need is to check a form submission

On Fri, Aug 28, 2009 at 10:55 AM, Eric  wrote:

>
> - Original Message -
> From: "Adam Jimerson" 
> To: 
> Sent: Friday, August 28, 2009 11:21 AM
> Subject: [PHP] Re: Best way to test for form submission?
>
>
> > On 08/27/2009 11:09 PM, Adam Jimerson wrote:
> >> This question might give away the fact that I am a php noob, but I am
> >> looking for the best way to test for form submission in PHP.  I know in
> >> Perl this can be done with
> >>
> >> if (param)
> >>
> >> but I don't know if that will work with PHP.  I have read the Learning
> >> PHP 5 book and the only thing that was mentioned in the book was the use
> >> of something like this
> >>
> >> print "Hello ".$_POST['username']."";
> >
> > Sorry copied and pasted the wrong line (long day)
> >
> > if (array_key_exists('username',$_POST))
>
> Here is another way
>
> if (isset($_POST['username'])  && $_POST['username'] != '')
> { ...
>
>
> >>
> >> I'm sure that this is not the best/recommended way to do this but I'm
> >> hoping someone here will point me in the right direction.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>



-- 
Martin Scotta


Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Eric

- Original Message - 
From: "Adam Jimerson" 
To: 
Sent: Friday, August 28, 2009 11:21 AM
Subject: [PHP] Re: Best way to test for form submission?


> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>> This question might give away the fact that I am a php noob, but I am
>> looking for the best way to test for form submission in PHP.  I know in
>> Perl this can be done with
>> 
>> if (param)
>> 
>> but I don't know if that will work with PHP.  I have read the Learning
>> PHP 5 book and the only thing that was mentioned in the book was the use
>> of something like this
>> 
>> print "Hello ".$_POST['username']."";
> 
> Sorry copied and pasted the wrong line (long day)
> 
> if (array_key_exists('username',$_POST))

Here is another way

if (isset($_POST['username'])  && $_POST['username'] != '')
{ ...


>> 
>> I'm sure that this is not the best/recommended way to do this but I'm
>> hoping someone here will point me in the right direction.
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Stuart
2009/8/28 Adam Jimerson :
> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
>> This question might give away the fact that I am a php noob, but I am
>> looking for the best way to test for form submission in PHP.  I know in
>> Perl this can be done with
>>
>> if (param)
>>
>> but I don't know if that will work with PHP.  I have read the Learning
>> PHP 5 book and the only thing that was mentioned in the book was the use
>> of something like this
>>
>> print "Hello ".$_POST['username']."";
>
> Sorry copied and pasted the wrong line (long day)
>
> if (array_key_exists('username',$_POST))
>>
>> I'm sure that this is not the best/recommended way to do this but I'm
>> hoping someone here will point me in the right direction.

Two options...

1) if (isset($_POST['username'])) // Specific to any given form

2) if (count($_POST) > 0) // Just tests whether any data was POSTed

There are other ways to do it but I usually use one of these two.

-Stuart

-- 
http://stut.net/

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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Ashley Sheridan
On Thu, 2009-08-27 at 23:21 -0400, Adam Jimerson wrote:
> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
> > This question might give away the fact that I am a php noob, but I am
> > looking for the best way to test for form submission in PHP.  I know in
> > Perl this can be done with
> > 
> > if (param)
> > 
> > but I don't know if that will work with PHP.  I have read the Learning
> > PHP 5 book and the only thing that was mentioned in the book was the use
> > of something like this
> > 
> > print "Hello ".$_POST['username']."";
> 
> Sorry copied and pasted the wrong line (long day)
> 
> if (array_key_exists('username',$_POST))
> > 
> > I'm sure that this is not the best/recommended way to do this but I'm
> > hoping someone here will point me in the right direction.
> 
> 

The best way I've found is to do something like this:

if(isset($_POST['submit']))
{}

Note that in-place of submit you can put the name of any form element. I
chose submit here, because every form should have a submit button. Note
also that this will only work if you have given your submit button a
name:



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




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



Re: [PHP] Re: Best way to test for form submission?

2009-08-28 Thread Nitsan Bin-Nun
";

On Fri, Aug 28, 2009 at 5:21 AM, Adam Jimerson  wrote:

> On 08/27/2009 11:09 PM, Adam Jimerson wrote:
> > This question might give away the fact that I am a php noob, but I am
> > looking for the best way to test for form submission in PHP.  I know in
> > Perl this can be done with
> >
> > if (param)
> >
> > but I don't know if that will work with PHP.  I have read the Learning
> > PHP 5 book and the only thing that was mentioned in the book was the use
> > of something like this
> >
> > print "Hello ".$_POST['username']."";
>
> Sorry copied and pasted the wrong line (long day)
>
> if (array_key_exists('username',$_POST))
> >
> > I'm sure that this is not the best/recommended way to do this but I'm
> > hoping someone here will point me in the right direction.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>