From 683a400d1e907afe22a6b879c19e293c29be6ece Mon Sep 17 00:00:00 2001 From: aphandersen Date: Wed, 15 Apr 2026 21:05:00 +0000 Subject: [PATCH] Upload files to "ansico-contact-form" --- ansico-contact-form/ansico-contact-form.php | 162 ++++++++++++++++++++ ansico-contact-form/block.js | 80 ++++++++++ ansico-contact-form/readme.txt | 44 ++++++ 3 files changed, 286 insertions(+) create mode 100644 ansico-contact-form/ansico-contact-form.php create mode 100644 ansico-contact-form/block.js create mode 100644 ansico-contact-form/readme.txt diff --git a/ansico-contact-form/ansico-contact-form.php b/ansico-contact-form/ansico-contact-form.php new file mode 100644 index 0000000..be0f59e --- /dev/null +++ b/ansico-contact-form/ansico-contact-form.php @@ -0,0 +1,162 @@ +' . esc_html($spam_err_msg) . '

'; + } else { + if (!$form_processed_once) { + ansico_cf_v1_send_final_mail($posted_name, $posted_email, $posted_subject, $posted_message, $recipient, $format, $footer_msg, $label_name, $label_email, $label_subj, $label_msg); + $form_processed_once = true; + } + $msg_html = '

' . esc_html($success_msg) . '

'; + $posted_name = $posted_email = $posted_subject = $posted_message = ''; + } + } + + $num1 = rand(1, 5); + $num2 = rand(1, 5); + $expected = $num1 + $num2; + + ob_start(); + ?> +
+ +
+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + + +

+

+ + +

+
+
+ '; + $headers[] = 'From: ' . $name . ' <' . $email . '>'; + + if ($format === 'html') { + $body = "" . esc_html($l_name) . ": " . esc_html($name) . "
"; + $body .= "" . esc_html($l_email) . ": " . esc_html($email) . "
"; + $body .= "" . esc_html($l_subj) . ": " . esc_html($subject) . "

"; + $body .= "" . esc_html($l_msg) . ":
" . nl2br(esc_html($message)) . "

"; + $body .= "
" . esc_html($footer_msg) . " " . esc_html($site_name) . ""; + } else { + $body = $l_name . ": " . $name . "\n"; + $body .= $l_email . ": " . $email . "\n"; + $body .= $l_subj . ": " . $subject . "\n\n"; + $body .= $l_msg . ":\n" . $message . "\n\n"; + $body .= "---\n" . $footer_msg . " " . $site_name; + } + + wp_mail($to, $subject, $body, $headers); +} + +/** + * Register the Gutenberg block. + */ +function ansico_cf_v1_init() { + wp_register_script( + 'ansico-cf-js', + plugins_url('block.js', __FILE__), + array('wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components'), + '1.0.0' + ); + + register_block_type('ansico/contact-form', array( + 'editor_script' => 'ansico-cf-js', + 'render_callback' => 'ansico_cf_v1_render_callback', + 'attributes' => array( + 'blockId' => array('type' => 'string', 'default' => ''), + 'recipientEmail' => array('type' => 'string', 'default' => ''), + 'successMessage' => array('type' => 'string', 'default' => 'Message has been sent'), + 'spamErrorMessage' => array('type' => 'string', 'default' => 'Wrong spam protection answer.'), + 'footerMessage' => array('type' => 'string', 'default' => 'Message has been sent on website'), + 'emailFormat' => array('type' => 'string', 'default' => 'text'), + 'labelName' => array('type' => 'string', 'default' => 'Name'), + 'labelEmail' => array('type' => 'string', 'default' => 'E-mail'), + 'labelSubject' => array('type' => 'string', 'default' => 'Subject'), + 'labelMessage' => array('type' => 'string', 'default' => 'Message'), + 'labelSpam' => array('type' => 'string', 'default' => 'Spam check:'), + 'buttonText' => array('type' => 'string', 'default' => 'Send message'), + ) + )); +} +add_action('init', 'ansico_cf_v1_init'); diff --git a/ansico-contact-form/block.js b/ansico-contact-form/block.js new file mode 100644 index 0000000..2f9fee4 --- /dev/null +++ b/ansico-contact-form/block.js @@ -0,0 +1,80 @@ +(function(wp) { + const { registerBlockType } = wp.blocks; + const { createElement: el } = wp.element; + const { InspectorControls } = wp.blockEditor || wp.editor; + const { PanelBody, TextControl, SelectControl } = wp.components; + + registerBlockType('ansico/contact-form', { + title: 'Ansico Contact Form', + icon: 'email', + category: 'common', + attributes: { + blockId: { type: 'string', default: '' }, + recipientEmail: { type: 'string', default: '' }, + successMessage: { type: 'string', default: 'Message has been sent' }, + spamErrorMessage: { type: 'string', default: 'Wrong spam protection answer.' }, + footerMessage: { type: 'string', default: 'Message has been sent on website' }, + emailFormat: { type: 'string', default: 'text' }, + labelName: { type: 'string', default: 'Name' }, + labelEmail: { type: 'string', default: 'E-mail' }, + labelSubject: { type: 'string', default: 'Subject' }, + labelMessage: { type: 'string', default: 'Message' }, + labelSpam: { type: 'string', default: 'Spam check:' }, + buttonText: { type: 'string', default: 'Send message' } + }, + edit: function(props) { + const { attributes, setAttributes } = props; + + if (!attributes.blockId) { + setAttributes({ blockId: Math.random().toString(36).substr(2, 9) }); + } + + const sidebar = el(InspectorControls, null, + el(PanelBody, { title: 'Email Settings', initialOpen: true }, + el(TextControl, { label: 'Recipient Email (Blank = Site Admin)', value: attributes.recipientEmail, onChange: (val) => setAttributes({ recipientEmail: val }) }), + el(SelectControl, { label: 'Email Format', value: attributes.emailFormat, options: [{label: 'Plain Text', value: 'text'}, {label: 'HTML', value: 'html'}], onChange: (val) => setAttributes({ emailFormat: val }) }), + el(TextControl, { label: 'Success Message', value: attributes.successMessage, onChange: (val) => setAttributes({ successMessage: val }) }), + el(TextControl, { label: 'Spam Error Message', value: attributes.spamErrorMessage, onChange: (val) => setAttributes({ spamErrorMessage: val }) }), + el(TextControl, { label: 'Email Footer Text', value: attributes.footerMessage, onChange: (val) => setAttributes({ footerMessage: val }) }) + ), + el(PanelBody, { title: 'Form Labels & Buttons', initialOpen: false }, + el(TextControl, { label: 'Name Label', value: attributes.labelName, onChange: (val) => setAttributes({ labelName: val }) }), + el(TextControl, { label: 'Email Label', value: attributes.labelEmail, onChange: (val) => setAttributes({ labelEmail: val }) }), + el(TextControl, { label: 'Subject Label', value: attributes.labelSubject, onChange: (val) => setAttributes({ labelSubject: val }) }), + el(TextControl, { label: 'Message Label', value: attributes.labelMessage, onChange: (val) => setAttributes({ labelMessage: val }) }), + el(TextControl, { label: 'Spam Check Label', value: attributes.labelSpam, onChange: (val) => setAttributes({ labelSpam: val }) }), + el(TextControl, { label: 'Button Text', value: attributes.buttonText, onChange: (val) => setAttributes({ buttonText: val }) }) + ) + ); + + const formPreview = el('div', { style: { maxWidth: '500px', fontFamily: 'inherit' } }, + el('div', { style: { marginBottom: '15px' } }, + el('label', { style: { fontWeight: '600', display: 'block', marginBottom: '5px' } }, attributes.labelName), + el('input', { type: 'text', disabled: true, style: { width: '100%', padding: '10px', border: '1px solid #ccc', borderRadius: '4px' } }) + ), + el('div', { style: { marginBottom: '15px' } }, + el('label', { style: { fontWeight: '600', display: 'block', marginBottom: '5px' } }, attributes.labelEmail), + el('input', { type: 'email', disabled: true, style: { width: '100%', padding: '10px', border: '1px solid #ccc', borderRadius: '4px' } }) + ), + el('div', { style: { marginBottom: '15px' } }, + el('label', { style: { fontWeight: '600', display: 'block', marginBottom: '5px' } }, attributes.labelSubject), + el('input', { type: 'text', disabled: true, style: { width: '100%', padding: '10px', border: '1px solid #ccc', borderRadius: '4px' } }) + ), + el('div', { style: { marginBottom: '15px' } }, + el('label', { style: { fontWeight: '600', display: 'block', marginBottom: '5px' } }, attributes.labelMessage), + el('textarea', { disabled: true, rows: 4, style: { width: '100%', padding: '10px', border: '1px solid #ccc', borderRadius: '4px', resize: 'none' } }) + ), + el('div', { style: { marginBottom: '20px' } }, + el('label', { style: { fontWeight: '600', display: 'block', marginBottom: '5px' } }, attributes.labelSpam + ' 2 + 3 = ?'), + el('input', { type: 'text', disabled: true, style: { width: '100%', padding: '10px', border: '1px solid #ccc', borderRadius: '4px' } }) + ), + el('button', { disabled: true, style: { padding: '12px 24px', background: '#007cba', color: '#fff', border: 'none', borderRadius: '4px', fontWeight: 'bold' } }, attributes.buttonText) + ); + + return el('div', null, sidebar, formPreview); + }, + save: function() { + return null; + } + }); +})(window.wp); diff --git a/ansico-contact-form/readme.txt b/ansico-contact-form/readme.txt new file mode 100644 index 0000000..b9d745d --- /dev/null +++ b/ansico-contact-form/readme.txt @@ -0,0 +1,44 @@ +=== Ansico Contact Form === +Contributors: ansico +Tags: contact form, gutenberg, block, spam protection, customizable +Requires at least: 5.8 +Tested up to: 6.9.4 +Stable tag: 1.0.0 +License: GPLv3 or later +License URI: https://www.gnu.org/licenses/gpl-3.0.html + +A lightweight, fully customizable contact form block for the Gutenberg editor with built-in math spam protection. + +== Description == + +Ansico Contact Form is a simple yet powerful Gutenberg block that allows you to add contact forms to any page or post. Every label, button, and message is customizable directly within the editor. + +Key features: +* Native Gutenberg block. +* Math-based spam protection. +* Supports both Plain Text and HTML emails. +* Customizable labels for all fields. +* Customizable success and error messages. +* Remembers user input if spam check fails. +* Individual block settings. + +== Installation == + +1. Upload the plugin files to the `/wp-content/plugins/ansico-contact-form` directory, or install the plugin through the WordPress plugins screen directly. +2. Activate the plugin through the 'Plugins' screen in WordPress. +3. Search for the "Ansico Contact Form" block in the editor and add it to your page. + +== Screenshots == + +1. The contact form block settings in the Gutenberg sidebar. +2. The contact form as it appears on the frontend. + +== Changelog == + += 1.0.0 = +* Official production release. +* Added readme.txt for WordPress.org compliance. +* Set sender email to use the user's inputted email address. +* Improved email headers to show sender name. +* Included all field data in the email body. +* Fixed double-sending issues.