Hello I'm watching a tutorial about OOP PHP "How to make login form". And I can't understand how the form post was gotten from this code.
您好我正在观看有关OOP PHP“如何制作登录表单”的教程。我无法理解表格帖子是如何从这段代码中获得的。
input.php
input.php
class input
{
public static function exists($type = 'post')
{
switch ($type)
{
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
}
register.php
register.php
if (input::exists())
{
//the submit button was clicked
}
So I will be happy if someone explain how does that work and how can i specify it to a specific form. Like this.
如果有人解释这是如何工作的,我将很高兴,如何将其指定为特定形式。喜欢这个。
if ($_POST['specific submit name'])
{
// the specific submit button was clicked.
}
1 个解决方案
#1
1
This function:
这个功能:
public static function exists($type = 'post')
{
switch ($type)
{
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
checks if the $_POST
or $_GET
superglobal arrays are empty. So let's say that you need to check if a POST requests has reached your page. You call input::exists('post');
That means the first case is true and this part of the code will be executed:
检查$ _POST或$ _GET超全局数组是否为空。因此,假设您需要检查POST请求是否已到达您的页面。你调用input :: exists('post');这意味着第一种情况是正确的,这部分代码将被执行:
return (!empty($_POST)) ? true : false;
return(!empty($ _ POST))?真假;
This code returns true
if $_POST
is not empty, which practically means there's data in it or false
if it is empty. Truth be told, this statement could be more easily written like this:
如果$ _POST不为空,则此代码返回true,这实际上意味着其中包含数据,如果为空,则返回false。说实话,这句话可以更容易地写成:
return !empty($_POST);
return!empty($ _ POST);
The if/else logic is pretty reduntant as is most of that code. To check if a particular value is in the $_POST
array you can use isset
.
if / else逻辑与大多数代码一样非常简洁。要检查特定值是否在$ _POST数组中,您可以使用isset。
So let's say you submit a form or send an AJAX request and one of the fields has a name of 'foo', you can check if 'foo' exists in $_POST
like this:
因此,假设您提交表单或发送一个AJAX请求,其中一个字段的名称为'foo',您可以检查$ _POST中是否存在'foo',如下所示:
if(isset($_POST['foo'])
{
//do something with foo
}
As you can see there are simpler ways to check if $_POST
is populated and with what values. As I said above I consider the input
class and the exists
method reduntant code. You could use this tutorial just for learning what OOP is but I wouldn't rely on it
正如您所看到的,有更简单的方法可以检查是否填充了$ _POST以及具有什么值。如上所述,我考虑输入类和存在方法reduntant代码。你可以使用本教程来学习OOP是什么,但我不会依赖它
#1
1
This function:
这个功能:
public static function exists($type = 'post')
{
switch ($type)
{
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
checks if the $_POST
or $_GET
superglobal arrays are empty. So let's say that you need to check if a POST requests has reached your page. You call input::exists('post');
That means the first case is true and this part of the code will be executed:
检查$ _POST或$ _GET超全局数组是否为空。因此,假设您需要检查POST请求是否已到达您的页面。你调用input :: exists('post');这意味着第一种情况是正确的,这部分代码将被执行:
return (!empty($_POST)) ? true : false;
return(!empty($ _ POST))?真假;
This code returns true
if $_POST
is not empty, which practically means there's data in it or false
if it is empty. Truth be told, this statement could be more easily written like this:
如果$ _POST不为空,则此代码返回true,这实际上意味着其中包含数据,如果为空,则返回false。说实话,这句话可以更容易地写成:
return !empty($_POST);
return!empty($ _ POST);
The if/else logic is pretty reduntant as is most of that code. To check if a particular value is in the $_POST
array you can use isset
.
if / else逻辑与大多数代码一样非常简洁。要检查特定值是否在$ _POST数组中,您可以使用isset。
So let's say you submit a form or send an AJAX request and one of the fields has a name of 'foo', you can check if 'foo' exists in $_POST
like this:
因此,假设您提交表单或发送一个AJAX请求,其中一个字段的名称为'foo',您可以检查$ _POST中是否存在'foo',如下所示:
if(isset($_POST['foo'])
{
//do something with foo
}
As you can see there are simpler ways to check if $_POST
is populated and with what values. As I said above I consider the input
class and the exists
method reduntant code. You could use this tutorial just for learning what OOP is but I wouldn't rely on it
正如您所看到的,有更简单的方法可以检查是否填充了$ _POST以及具有什么值。如上所述,我考虑输入类和存在方法reduntant代码。你可以使用本教程来学习OOP是什么,但我不会依赖它