php 如果值不以ftp:// http://或https://开头,则将check_website_field_value用于所有表单字段,并将http://添加到值的起点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 如果值不以ftp:// http://或https://开头,则将check_website_field_value用于所有表单字段,并将http://添加到值的起点相关的知识,希望对你有一定的参考价值。

add_filter('gform_pre_render', 'form_check_website_field_value');
add_filter('gform_pre_validation', 'form_check_website_field_value');

function form_check_website_field_value($form) {
    foreach ($form['fields'] as &$field) {  // for all form fields
        if ('website' == $field['type'] || ( isset($field['inputType']) && 'website' == $field['inputType'])) {  // select the fields that are 'website' type
            $value = RGFormsModel::get_field_value($field);  // get the value of the field
            if (!empty($value)) { // if value not empty
                $field_id = $field['id'];  // get the field id
                if (!preg_match("~^(?:f|ht)tps?://~i", $value)) {  // if value does not start with ftp:// http:// or https://
                    $value = "http://" . $value;  // add http:// to start of value
                }
                $_POST['input_' . $field_id] = $value; // update post with new value
            }
        }
    }
    return $form;
}

以上是关于php 如果值不以ftp:// http://或https://开头,则将check_website_field_value用于所有表单字段,并将http://添加到值的起点的主要内容,如果未能解决你的问题,请参考以下文章

nginx之防盗链

PHP文件通过FTP上传,报错“HTTP404",怎么解决?

PHP ftp_site() 函数

Laravel。存储:FTP,S3还是?对于非常大的文件[关闭]

php POST上传和FTP上传哪个好 为啥

怎么通过PHP来支持FTP和HTTP上传