Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19068 > unrolled thread
| Started by | Jakub <jak74@interia.pl> |
|---|---|
| First post | 2022-08-11 11:47 +0200 |
| Last post | 2022-09-22 07:12 -0700 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.php
How to validate $_POST array Jakub <jak74@interia.pl> - 2022-08-11 11:47 +0200
Re: How to validate $_POST array Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-08-11 14:43 +0000
Re: How to validate $_POST array Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-08-11 14:49 +0000
Re: How to validate $_POST array Arno Welzel <usenet@arnowelzel.de> - 2022-08-11 17:43 +0200
Re: How to validate $_POST array "He, who travels time to time" <he1983912@aol.com> - 2022-09-22 07:12 -0700
| From | Jakub <jak74@interia.pl> |
|---|---|
| Date | 2022-08-11 11:47 +0200 |
| Subject | How to validate $_POST array |
| Message-ID | <62f4cfff$0$568$65785112@news.neostrada.pl> |
I have this code
if ( isset($_POST) ) {
}
how to do filter_has_var function to check if $_POST exist and have value?
[toc] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2022-08-11 14:43 +0000 |
| Message-ID | <td34it$26lbt$1@dont-email.me> |
| In reply to | #19068 |
On Thu, 11 Aug 2022 11:47:02 +0200, Jakub wrote:
> I have this code
>
> if ( isset($_POST) ) {
>
> }
>
> how to do filter_has_var function to check if $_POST exist and have value?
If the originating web page has issues a POST, then
$_SERVER['REQUEST_METHOD'] will equal 'POST'
Your php code can only extract from the POST values that were set by
the web page when it issued the POST. It can't demand a specific value,
but it can establish whether or not the page supplied a specific value.
Say, for instance, you expect that the page will supply a text string
in a variable called 'TextString', you can check to see if
$_POST['TextString'] is set, and validate it's contents.
So, your php logic might look like
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if (isset($_POST['TextString']))
{
/* validate the contents of $_POST['TextString'] */
}
else
{
/* page didn't supply 'TextString'. Handle this situation */
}
}
else
{
/* page didn't POST. Handle the situation. */
}
HTH
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2022-08-11 14:49 +0000 |
| Message-ID | <td34ss$26lbt$2@dont-email.me> |
| In reply to | #19069 |
On Thu, 11 Aug 2022 14:43:41 +0000, Lew Pitcher wrote:
> On Thu, 11 Aug 2022 11:47:02 +0200, Jakub wrote:
>
>> I have this code
>>
>> if ( isset($_POST) ) {
>>
>> }
>>
>> how to do filter_has_var function to check if $_POST exist and have value?
>
> If the originating web page has issues a POST, then
> $_SERVER['REQUEST_METHOD'] will equal 'POST'
>
> Your php code can only extract from the POST values that were set by
> the web page when it issued the POST. It can't demand a specific value,
> but it can establish whether or not the page supplied a specific value.
>
> Say, for instance, you expect that the page will supply a text string
> in a variable called 'TextString', you can check to see if
> $_POST['TextString'] is set, and validate it's contents.
>
> So, your php logic might look like
>
> if ($_SERVER['REQUEST_METHOD'] == "POST")
> {
> if (isset($_POST['TextString']))
> {
> /* validate the contents of $_POST['TextString'] */
> }
> else
> {
> /* page didn't supply 'TextString'. Handle this situation */
> }
> }
> else
> {
> /* page didn't POST. Handle the situation. */
> }
Note that $_POST is an array, so you /can/ iterate across the values in it
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
foreach ($_POST as $pKEY => $pVALU)
{
/*
** $pKEY is the subscript to $_POST,
** $pVALU is the value carried by $_POST[$pKEY]
** use $pKEY to choose your $pVALU validation criteria
*/
}
}
else
{
/* page didn't POST. Handle the situation. */
}
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2022-08-11 17:43 +0200 |
| Message-ID | <jlkmchFd0r6U1@mid.individual.net> |
| In reply to | #19068 |
Jakub, 2022-08-11 11:47:
> I have this code
>
> if ( isset($_POST) ) {
>
> }
>
> how to do filter_has_var function to check if $_POST exist and have value?
See <https://www.php.net/manual/en/function.filter-has-var.php>.
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | "He, who travels time to time" <he1983912@aol.com> |
|---|---|
| Date | 2022-09-22 07:12 -0700 |
| Message-ID | <2b1cf8f4-6714-4914-8830-773047de4dc3n@googlegroups.com> |
| In reply to | #19068 |
Hey... Want to talk? Call me.... My telephone number >>>>
(+372) 56330687
Jakub kirjutas Neljapäev, 11. august 2022 kl 12:46:47 UTC+3:
> I have this code
>
> if ( isset($_POST) ) {
>
> }
>
> how to do filter_has_var function to check if $_POST exist and have value?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web