develtio/wp-forms

让表单变得可行

安装次数: 1,442

依赖者: 0

建议者: 0

安全: 0

星级: 2

关注者: 11

分支: 0

类型:wordpress-muplugin

1.10.1 2022-03-01 11:39 UTC

README

Develtio 表单

一个允许您创建和管理表单的插件。每个创建的表单都会生成一个新的文章类型,并将所有发送的数据作为单独的字段保存在 WP 管理。

使用方法

我们使用 Nette From 库来构建表单(https://doc.nette.org/en/3.0/forms

示例

if ( class_exists( '\Develtio\WP\Forms\Modules\Forms\CreateForm' ) ) {
    $options = [ 
        'send_mail' => true, // enables / disables sending an email, enabled by default
        'send_confirm_mail' => true // enables / disables sending of confirmation email, disabled by default
    ];

    $instance = new \Develtio\WP\Forms\Modules\Forms\CreateForm('Sample Form', $options);
    
    $mail = $instance->mail;
    $mail->setFrom(['noreply@example.com' => 'Sample form']);
    $mail->setTo(['info@example.com']);
    $mail->setTitle('Mail title');
    $mail->setConfirmMailField('contact_email'); // optional, if we send a confirmation e-mail, enter the name of the field from which the e-mail address is to be retrieved


    $form = $instance->form; // Nette Forms Instance
    $form->addText('contact_name')->setHtmlAttribute('placeholder', __('Name', 'develtio'));
    $form->addEmail( 'contact_email' )->setHtmlAttribute( 'placeholder', __( 'E-mail' ) )->setRequired( true );    

    $instance->save(); // Generate a form and post type
}

CPT 的 CSV 导出示例

    $options = [ 
        'send_mail' => true, // enables / disables sending an email, enabled by default
        'send_confirm_mail' => true // enables / disables sending of confirmation email, disabled by default
        'csv_export' => true,
        'csv_export_fields' => [
            'id' => 'ID',
            'date' => 'Created At',
            'form_name' => 'Name',
            'form_surname' => 'Surname',
            'form_email' => 'Email',
            'form_phone' => 'Phone',
            'form_specialization' => 'Specialization',
            'form_experience' => 'Experience',
            'form_description' => 'Description',
            'form_linkedin' => 'LinkedIn',
            'form_cv' => 'CV',
            'form_consent' => 'Consent'
        ]
    ];

模板

表单模板

默认情况下,字段将并列显示,Nette Forms 提供了以下这种显示方式的修改 https://doc.nette.org/en/3.0/form-rendering 或者,如果您想将表单用作短代码,您可以手动设置表单的显示方式,使用 $instance->setTemplate($template); 和特殊字段名称 field-name_fieldfield-name_error

示例
<form method="post" action="/" class="form--default" enctype="multipart/form-data">
    <div class="row">
        <div class="col-md-12">
            {contact_name_field}
            {contact_name_error}
        </div>
        <div class="col-md-12">
            {contact_email_field}
            {contact_email_error}
        </div>
    </div>
    <div class="row">
        <div class="col-md-24">
            <button type="submit">Send</button>
        </div>
    </div>
</div>

如果不会使用短代码,您可以使用 $form['field-name']->control$form['field-name']->error 而不是 field-name_fieldfield-name_error 来创建模板。

成功模板

您可以这样自定义感谢信息

    $instance->setSuccessTemplate('<p>Thank you for contacting us</p>');

确认模板

邮件模板

在应该显示数据的地方放置 {content} 字符串。

显示

表单可以以两种方式显示。您可以根据实例 $instance->form 创建自己的函数,并在页面的适当位置显示它,或者您可以使用从表单名称自动生成的短代码,例如 Sample form 创建 [sample-form] 短代码。