javascript 删除字段“联系表7”中的必填项

vlju58qv  于 2023-02-15  发布在  Java
关注(0)|答案(1)|浏览(81)

是否可以从放置在表单中的字段中删除此属性或类?
我有一些字段是必填的,但由于一个奇怪的原因,它将所有字段都标记为必填

<label>Name:
[text* your-name] </label>

<label>Phone: 
[tel* telefono]</label>

<label>Account (format: xxxx-xxxx-xx)
[text* presupuestaria]</label>

<p>How many pages does your document have?
[text totalpaginas]</p>

<p>What is the Number of Copies do you need?::
[text canticopia]</p>

<p>It is confidential?[select confiden id:confidenselect "No" "Si"]</p>
[group group-999 clear_on_hide inline]
<div id="confident">Data of the person who will withdraw the copies
<p>Name:[text sinombrefoto]</p>
<p>Email: [text siemailfoto]</p>
</div>
[/group]
<p style=”float:right”>
[submit “Submit”]
</p>

我尝试发送表单,但它告诉我有空字段,并且这些字段(如代码中所示)不是必需的

<input type="text" name="totalpaginas" value="" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" required="">
t5fffqht

t5fffqht1#

要从一个字段中删除验证,您需要添加筛选器:

function so73691953_validation_filter($result,$tag){
        $name = $tag->name;
        $exception_fields = array(
            'totalpaginas'
        );
        if (in_array($name, $exception_fields)) {
            return $result;
        }
        if($_POST[$name] == '') {
            $result->invalidate( $tag, "This field cannot be empty.");
        }
    return $result;
}   
add_filter( 'wpcf7_validate_text*', 'so73691953_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text', 'so73691953_validation_filter', 10, 2 );

此过滤器验证除$exception_fields数组中定义的输入名称之外的所有字段是否均为非空

相关问题