Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 验证动态WP表单中的必填字段_Php_Wordpress_Validation - Fatal编程技术网

Php 验证动态WP表单中的必填字段

Php 验证动态WP表单中的必填字段,php,wordpress,validation,Php,Wordpress,Validation,因此,我使用一个简单的字段数组创建一个表单: $fields = array( array( 'label' => 'Name:', 'id' => $meta.'_nhm_lead_name', 'class' => 'field-name input', // optional 'wrapper_class' => 'four columns', // optional '

因此,我使用一个简单的字段数组创建一个表单:

    $fields = array(
    array(
        'label' => 'Name:',
        'id' => $meta.'_nhm_lead_name',
        'class' => 'field-name input', // optional
        'wrapper_class' => 'four columns', // optional
        'type' => 'text',
        'required' => true,
    ),
    );
然后使用一个简单的开关函数(如下所示)对其进行回音:

    public function make_fields(){

    foreach($this->fields as $field => $value){
        switch ($value['type']) {
            case 'text':
                $inputs .= '<li class="field '.$value['wrapper_class'].'">';
                if($this->labels == true){
                    $inputs .= '<label for="'.$value['id'].'">'.$value['label'].'</label>';
                }
                $inputs .= '<input type="text" name="'.$value['id'].'" class="'.$value['class'].'" />';
                $inputs .= '<span class="error-message"></span>';
                $inputs .= '</li>';
            break;
        }
    }
    }
公共函数make_字段(){
foreach($this->fields as$field=>$value){
开关($value['type'])){
案例“文本”:
$inputs.='
  • ”; 如果($this->labels==true){ $inputs.=''.$value['label'].'; } $inputs.=''; $inputs.=''; $inputs.='
  • '; 打破 } } }

    我遇到的问题是,当我将它们发布到我的邮件处理表单时,我无法验证它们是否是必需的以及它们是什么类型的字段。我该怎么办?这也是为Wordpress构建的表单

    这将在客户端起作用

    public function make_fields(){
    
    foreach($this->fields as $field => $value){
        $required = "NULL";
          if($value['required'] == "yes") {
                $required = 'required="required"';   
            }
        switch ($value['type']) {
            case 'text':
                $inputs .= '<li class="field '.$value['wrapper_class'].'">';
                if($this->labels == true){
                    $inputs .= '<label for="'.$value['id'].'">'.$value['label'].'</label>';
                }
                $inputs .= '<input type="text" $required name="'.$value['id'].'" class="'.$value['class'].'" />';
                $inputs .= '<span class="error-message"></span>';
                $inputs .= '</li>';
            break;
        }
    }
    }
    
    公共函数make_字段(){
    foreach($this->fields as$field=>$value){
    $required=“NULL”;
    如果($value['required']==“yes”){
    $required='required=“required”';
    }
    开关($value['type'])){
    案例“文本”:
    $inputs.='
  • ”; 如果($this->labels==true){ $inputs.=''.$value['label'].'; } $inputs.=''; $inputs.=''; $inputs.='
  • '; 打破 } } }
    也许您可以添加隐藏字段,其中包含所有必填字段的数据。然后在服务器端可以映射它。但从安全角度来看,这不是一个好方法。谢谢你的帮助。我现在如何在服务器端检查呢?为此,我在您的问题中添加了注释。