Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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 wordpress-在表单中标记wp_编辑器必填字段_Php_Wordpress_Validation_Wp Editor - Fatal编程技术网

Php wordpress-在表单中标记wp_编辑器必填字段

Php wordpress-在表单中标记wp_编辑器必填字段,php,wordpress,validation,wp-editor,Php,Wordpress,Validation,Wp Editor,我正在为wordpress开发一个前端表单,我在表单中为文本区域添加了wp\u编辑器,下面是我添加的代码。是否有任何方法可以将此字段标记为必填字段,就像HTML5必填参数一样 <?php $settings = array( 'wpautop' => false, 'media_buttons' => true, 'textarea_rows' => 5, 'tinymce' => true, 'teeny' =>

我正在为wordpress开发一个前端表单,我在表单中为文本区域添加了
wp\u编辑器
,下面是我添加的代码。是否有任何方法可以将此字段标记为必填字段,就像HTML5必填参数一样

<?php
    $settings = array(
    'wpautop' => false,
    'media_buttons' => true,
    'textarea_rows' => 5,
    'tinymce' => true,
    'teeny' => true,
    'textarea_name' => 'main_Content',
    'quicktags' => false,
    'editor_height' => 300
);

    $content = '';
    $editor_id = 'main_Content';

    wp_editor(stripslashes($content), $editor_id, $settings);
?>

可视化编辑器不是文本区域,而是iframe,因此即使 您可以设置一个属性,但它不会起任何作用。您可以设置 属性,该属性位于将发送到服务器但 由于它是隐藏的,我不知道如何提醒它没有被发现 将显示“已填充”,不同浏览器之间可能会有所不同 (它是隐藏的,因此没有明显的视觉定位来显示 (警报)

否则

您可以向html编辑器添加过滤器

add_filter('the_editor','add_required_attribute_to_wp_editor',10,1);
函数添加所需的属性到编辑器($editor){
$editor=str_replace('
可视化编辑器不是文本区域,而是iframe,因此即使
您可以设置一个属性,它将不起任何作用。您可以设置
属性,该属性位于将发送到服务器但
由于它是隐藏的,我不知道如何提醒它没有被发现
将显示“已填充”,不同浏览器之间可能会有所不同
(它是隐藏的,因此没有明显的视觉定位来显示
(警报)

否则

您可以向html编辑器添加过滤器

add_filter('the_editor','add_required_attribute_to_wp_editor',10,1);
函数添加所需的属性到编辑器($editor){

$editor=str_replace(“对于在管理屏幕上使用多个可视化编辑器(只需要其中一些)的插件,我已经成功地完成了以下操作

  • 在创建编辑器时,添加一个对我的插件唯一的类,并指示此编辑器中需要内容
  • 将函数挂接到“theu编辑器”
  • 此函数将检查编辑器的标记是否包含自定义类。如果包含自定义类,则添加所需的属性
  • 我能够使用

    textarea[required]:invalid
    
    如果表单在该字段为空时提交,则会生成一个错误(尽管到目前为止我只在Safari 10.1中进行了测试)

    下面是示例代码(此代码取自一个更大的类)。 首先,从构建编辑器的函数中摘录

    $addlClass = ($required) ? 'my-required-field' : '';
    $settings  = array(
      'media_buttons' => false,
      'textarea_name' => $fieldName,
      'editor_class'  => $addlClass
    );
    wp_editor($cleanFld, $fieldId, $settings);
    
    然后,我的钩子:

    add_action('the_editor', array($this, 'CheckIfEditorFieldIsRequired'));
    
    最后,该职能:

    public function CheckIfEditorFieldIsRequired($editorMarkup)
    {
      if (stripos($editorMarkup, 'my-required-field') !== false) {
        $editorMarkup = str_replace('<textarea', '<textarea required', $editorMarkup);
      }
      return $editorMarkup;
    }
    
    public函数CheckIfEditorFieldIsRequired($editorMarkup)
    {
    if(stripos($editorMarkup,'my required field')!==false){
    
    $editorMarkup=str_replace(“对于在管理屏幕上使用多个可视编辑器(只需要其中一些)的插件,我已经成功地完成了以下操作

  • 在创建编辑器时,添加一个对我的插件唯一的类,并指示此编辑器中需要内容
  • 将函数挂接到“theu编辑器”
  • 此函数将检查编辑器的标记是否包含自定义类。如果包含自定义类,则添加所需的属性
  • 我能够使用

    textarea[required]:invalid
    
    如果表单在该字段为空时提交,则会生成一个错误(尽管到目前为止我只在Safari 10.1中进行了测试)

    下面是示例代码(此代码取自一个更大的类)。 首先,从构建编辑器的函数中摘录

    $addlClass = ($required) ? 'my-required-field' : '';
    $settings  = array(
      'media_buttons' => false,
      'textarea_name' => $fieldName,
      'editor_class'  => $addlClass
    );
    wp_editor($cleanFld, $fieldId, $settings);
    
    然后,我的钩子:

    add_action('the_editor', array($this, 'CheckIfEditorFieldIsRequired'));
    
    最后,该职能:

    public function CheckIfEditorFieldIsRequired($editorMarkup)
    {
      if (stripos($editorMarkup, 'my-required-field') !== false) {
        $editorMarkup = str_replace('<textarea', '<textarea required', $editorMarkup);
      }
      return $editorMarkup;
    }
    
    public函数CheckIfEditorFieldIsRequired($editorMarkup)
    {
    if(stripos($editorMarkup,'my required field')!==false){
    
    $editorMarkup=str_replace('进一步测试表明,这在当前的Chrome或Firefox版本中不起作用,至少目前不起作用。进一步测试表明,这在当前的Chrome或Firefox版本中不起作用,至少目前不起作用。