Compare commits

...
3 Commits
Author SHA1 Message Date
krzysiek 4c5924e5be Dodano readme.md 2026-11-17 00:51:36 +01:00
krzysiekandClaude Fable 5.2 0f7eddd6a0 Poprawki bezpieczeństwa formularza i panelu ustawień
- wp_unslash dla pól formularza i opcji (koniec z \' w mailach)
- panel: wymagany nonce i manage_options, sanityzacja, esc_attr
- reCAPTCHA: oczekiwana akcja i próg wyniku 0.5
- From z domeny strony, adres nadawcy tylko w Reply-To
- honeypot bez die(), walidacja JS nie jest omijana
- komunikat o nieudanej wysyłce, zachowanie wpisanych pól
- nowy wygląd formularza (klasy ic-*) i szablon maila

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-15 23:44:46 +01:00
krzysiek f6b707a6f2 Poprawiony shortcode 2026-03-10 22:15:33 +01:00
8 changed files with 701 additions and 325 deletions
+194 -56
View File
@@ -1,93 +1,231 @@
# InContact # InContact
Prosta wtyczka WordPress z formularzem kontaktowym wstawianym shortcode'em. Wysyła wiadomość jako sformatowany e-mail HTML, chroni się przed spamem honeypotem i opcjonalnie Google reCAPTCHA v3, a wszystkie etykiety ustawia się w panelu administracyjnym.
- **Wersja wtyczki:** 1.0.1
- **Autor:** Krzysztof Turek — [krzysztof-turek.com](https://krzysztof-turek.com)
- **Licencja:** GPL2
- **Text domain:** `in-contact`
## Getting started ## Spis treści
To make it easy for you to get started with GitLab, here's a list of recommended next steps. - [Funkcje](#funkcje)
- [Wymagania](#wymagania)
- [Instalacja](#instalacja)
- [Konfiguracja](#konfiguracja)
- [Użycie](#użycie)
- [Jak działa wysyłka](#jak-działa-wysyłka)
- [Ochrona przed spamem](#ochrona-przed-spamem)
- [Wygląd i stylowanie](#wygląd-i-stylowanie)
- [Tłumaczenia](#tłumaczenia)
- [Struktura projektu](#struktura-projektu)
- [Bezpieczeństwo](#bezpieczeństwo)
- [Znane ograniczenia](#znane-ograniczenia)
- [Rozwój](#rozwój)
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! ## Funkcje
## Add your files - Formularz z trzema polami: imię i nazwisko, e-mail, wiadomość.
- Wstawianie w dowolnym miejscu shortcode'em `[inContact]`.
- E-mail HTML z czytelnym szablonem: dane nadawcy, treść i przycisk „Odpowiedz na wiadomość”.
- Walidacja po stronie przeglądarki (bez jQuery i Bootstrapa) oraz po stronie serwera.
- Ochrona przed spamem: ukryte pole honeypot i opcjonalnie reCAPTCHA v3 z progiem wyniku.
- Komunikaty sukcesu i błędu; po nieudanej próbie wpisane dane zostają w polach.
- Panel ustawień w kokpicie WordPressa: klucze reCAPTCHA, adres odbiorcy, etykiety i placeholdery.
- Gotowe tłumaczenie na język polski (`pl_PL`).
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files ## Wymagania
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
| Składnik | Wersja |
| --- | --- |
| WordPress | 5.0 lub nowszy (zalecana aktualna wersja) |
| PHP | 7.3 lub nowszy |
| Wysyłka poczty | działające `wp_mail()` — najlepiej przez wtyczkę SMTP |
| reCAPTCHA (opcjonalnie) | klucze **reCAPTCHA v3** z [konsoli Google](https://www.google.com/recaptcha/admin) |
Wtyczka nie ma zależności instalowanych przez Composer ani npm. Biblioteka `google/recaptcha` (wersja 1.2.4) jest dołączona w katalogu `inc/classes/ReCaptcha`.
## Instalacja
1. Skopiuj katalog wtyczki do `wp-content/plugins/` (np. jako `wp-content/plugins/InContact`).
Możesz też spakować katalog do ZIP i wgrać go w **Wtyczki → Dodaj nową → Wyślij wtyczkę na serwer**.
2. Włącz wtyczkę **In Contact** w **Wtyczki → Zainstalowane wtyczki**.
3. W menu kokpitu pojawi się pozycja **InContact** — przejdź do [konfiguracji](#konfiguracja).
## Konfiguracja
Ustawienia znajdują się w **Kokpit → InContact** i są dostępne tylko dla użytkowników z uprawnieniem `manage_options` (administratorów).
| Pole w panelu | Opcja w bazie | Opis |
| --- | --- | --- |
| Klucz witryny | `incontact-site-key` | Klucz publiczny reCAPTCHA v3. Pusty = reCAPTCHA wyłączona. |
| Klucz tajny | `incontact-secret-key` | Klucz tajny reCAPTCHA v3. |
| Odbiorca (e-mail) | `incontact-target-mail` | Adres, na który trafiają wiadomości. Niepoprawny adres zostanie zapisany jako pusty. |
| Formularz – placeholder imienia | `incontact-form-ph-name` | Podpowiedź w polu imienia. |
| Formularz – placeholder e-maila | `incontact-form-ph-email` | Podpowiedź w polu e-mail. |
| Formularz – placeholder wiadomości | `incontact-form-ph-message` | Podpowiedź w polu wiadomości. |
| Formularz – etykieta imienia | `incontact-form-name` | Etykieta nad polem imienia. |
| Formularz – etykieta e-maila | `incontact-form-email` | Etykieta nad polem e-mail. |
| Formularz – etykieta wiadomości | `incontact-form-message` | Etykieta nad polem wiadomości. |
| Formularz – wiadomość wysłana | `incontact-form-snd-ok` | Komunikat wyświetlany po udanej wysyłce. |
Po świeżej instalacji wszystkie pola są puste — uzupełnij przynajmniej adres odbiorcy, etykiety i komunikat sukcesu.
### Konfiguracja reCAPTCHA v3
1. W [konsoli reCAPTCHA](https://www.google.com/recaptcha/admin) utwórz witrynę typu **reCAPTCHA v3** (nie v2 — wtyczka używa niewidocznego tokenu).
2. Dodaj domenę strony do listy domen.
3. Wklej klucz witryny i klucz tajny w panelu InContact i zapisz.
Wtyczka weryfikuje token po stronie serwera i wymaga:
- zgodnej nazwy hosta (`SERVER_NAME`),
- akcji `submit`,
- wyniku co najmniej **0.5**.
Jeśli prawdziwi użytkownicy są odrzucani, obniż próg w wywołaniu `setScoreThreshold(0.5)` w `inc/classes/inContact/Shortcode.php`.
## Użycie
Wstaw shortcode w treści strony lub wpisu (np. blokiem **Shortcode** w edytorze blokowym):
``` ```
cd existing_repo [inContact]
git remote add origin http://homelab.private.net/krzysiek/incontact.git
git branch -M main
git push -uf origin main
``` ```
## Integrate with your tools W szablonie motywu:
- [ ] [Set up project integrations](http://homelab.private.net/krzysiek/incontact/-/settings/integrations) ```php
<?php echo do_shortcode('[inContact]'); ?>
```
## Collaborate with your team Shortcode nie przyjmuje atrybutów — wszystkie teksty ustawia się w panelu.
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) ## Jak działa wysyłka
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy 1. Formularz wysyła żądanie `POST` na ten sam adres strony.
2. Serwer czyści dane (`wp_unslash` + `sanitize_text_field` / `sanitize_email` / `sanitize_textarea_field`) i sprawdza, czy pola są wypełnione oraz czy e-mail jest poprawny.
3. Jeśli reCAPTCHA jest włączona, token jest weryfikowany w Google.
4. Wiadomość wysyłana jest przez `wp_mail()` z nagłówkami:
Use the built-in continuous integration in GitLab. | Nagłówek | Wartość |
| --- | --- |
| `To` | adres z opcji `incontact-target-mail` |
| `Subject` | imię i nazwisko nadawcy |
| `From` | `Nazwa strony <wordpress@twoja-domena>` (domena z `home_url()`, bez `www.`) |
| `Reply-To` | `Imię Nazwisko <adres-nadawcy>` |
| `Content-Type` | `text/html; charset=UTF-8` |
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) Adres odwiedzającego trafia tylko do `Reply-To`, dzięki czemu wiadomość przechodzi kontrole SPF/DMARC, a „Odpowiedz” w programie pocztowym kieruje do nadawcy. Wtyczka SMTP z wymuszonym nadawcą nadpisze nagłówek `From`.
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
*** 5. Na stronie pojawia się komunikat sukcesu albo błędu („Nie udało się wysłać wiadomości. Spróbuj ponownie.”).
# Editing this README Wszystkie dane użytkownika w treści maila są escapowane (`esc_html`), a znaki nowej linii zamieniane na `<br />`.
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. ## Ochrona przed spamem
## Suggestions for a good README - **Honeypot** — ukryte pole `website`, niewidoczne dla ludzi. Jeśli bot je wypełni, dostaje zwykły komunikat sukcesu, ale mail nie jest wysyłany.
- **reCAPTCHA v3** — niewidoczna weryfikacja; token pobierany jest dopiero po przejściu walidacji formularza w przeglądarce.
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. ## Wygląd i stylowanie
## Name Style znajdują się w `css/inContact.css` i są ładowane tylko na stronach, na których użyto shortcode'u. Wszystkie klasy mają prefiks `ic-`, więc nie kolidują z motywem.
Choose a self-explaining name for your project.
## Description Kolory i zaokrąglenia ustawiane są zmiennymi CSS, które można nadpisać w motywie:
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges ```css
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. :root {
--ic-accent: #e2b04a;
--ic-accent-dark: #c49535;
--ic-radius: 4px;
}
```
## Visuals | Zmienna | Znaczenie |
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. | --- | --- |
| `--ic-bg`, `--ic-surface` | tło pól i kontenera |
| `--ic-border`, `--ic-border-focus` | obramowania |
| `--ic-text`, `--ic-text-muted` | tekst i placeholdery |
| `--ic-accent`, `--ic-accent-dark` | przycisk i jego stan `:hover` |
| `--ic-error`, `--ic-error-bg` | błędy walidacji |
| `--ic-success-bg`, `--ic-success-txt` | komunikat sukcesu |
| `--ic-radius`, `--ic-transition`, `--ic-font` | zaokrąglenia, animacje, czcionka |
## Installation Główne klasy: `.ic-wrap` (kontener), `.ic-field` (pole), `.ic-field--invalid` (pole z błędem), `.ic-field__error` (tekst błędu), `.ic-alert--success` / `.ic-alert--error` (komunikaty).
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage Plik `css/inContact-dark.css` zawiera wariant ciemny, ale nie jest obecnie ładowany przez wtyczkę.
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support ## Tłumaczenia
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap Pliki tłumaczeń znajdują się w katalogu `languages/`:
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing - `in-contact.pot` — szablon do nowych tłumaczeń,
State if you are open to contributions and what your requirements are for accepting them. - `in-contact-pl_PL.po` / `.mo` — tłumaczenie polskie.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. Teksty źródłowe są po angielsku. Aby dodać nowy język, utwórz plik `in-contact-xx_XX.po` z szablonu `.pot` (np. w Poedit) i skompiluj go do `.mo`. Po zmianie `.po` ręcznie:
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. ```bash
msgfmt -o languages/in-contact-pl_PL.mo languages/in-contact-pl_PL.po
```
## Authors and acknowledgment Etykiety i placeholdery formularza nie są tłumaczone automatycznie — pochodzą z panelu ustawień.
Show your appreciation to those who have contributed to the project.
## License ## Struktura projektu
For open source projects, say how it is licensed.
## Project status ```
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. InContact/
├── in-contact.php # plik główny: nagłówek wtyczki, stałe, autoloader, start
├── index.php # blokada listowania katalogu
├── css/
│ ├── inContact.css # style formularza (ładowane)
│ └── inContact-dark.css # wariant ciemny (nieładowany)
├── inc/
│ ├── autoload.php # autoloader: Namespace\Klasa → classes/Namespace/Klasa.php
│ └── classes/
│ ├── inContact/
│ │ ├── Init.php # inicjalizacja: tłumaczenia i pozostałe klasy
│ │ ├── Singleton.php # trait getInstance()
│ │ ├── AdminMenu.php # menu i strona ustawień w kokpicie
│ │ ├── Shortcode.php # shortcode [inContact]: formularz, walidacja, wysyłka
│ │ └── Enqueue.php # rejestracja stylów (obecnie nieużywana)
│ └── ReCaptcha/ # biblioteka google/recaptcha 1.2.4
└── languages/ # pliki .pot / .po / .mo
```
Przepływ: `in-contact.php` → `Init::getInstance()` → rejestracja `AdminMenu` (hook `admin_menu`) i `Shortcode` (`add_shortcode`).
## Bezpieczeństwo
- Zapis ustawień wymaga poprawnego nonce (`incontact-update`) i uprawnienia `manage_options`.
- Wszystkie opcje są czyszczone przy zapisie i escapowane przy wyświetlaniu (`esc_attr`, `esc_html`).
- Dane z formularza są czyszczone funkcjami WordPressa i escapowane w treści maila.
- Nagłówki `From` / `Reply-To` są oczyszczone ze znaków nowej linii i nawiasów, co zapobiega wstrzykiwaniu nagłówków.
- Klucz tajny reCAPTCHA jest przechowywany w tabeli `wp_options` i wyświetlany w panelu jako zwykłe pole tekstowe.
## Znane ograniczenia
- **Wysyłka podczas renderowania shortcode'u** — jeśli treść strony jest renderowana kilka razy (niektóre wtyczki SEO lub page buildery), mail może zostać wysłany więcej niż raz.
- **Ponowna wysyłka po odświeżeniu** — brak przekierowania po `POST`, więc odświeżenie strony po wysłaniu może wysłać wiadomość ponownie.
- **Brak limitu wysyłek** — bez reCAPTCHA jedyną ochroną jest honeypot.
- **Jeden formularz na stronę** — elementy mają stałe atrybuty `id`.
- **Temat maila** to samo imię i nazwisko nadawcy.
- Atrybut `lang="pl"` w szablonie maila jest ustawiony na stałe.
- Ustawienia nie są usuwane z bazy po odinstalowaniu wtyczki.
## Rozwój
Projekt nie ma procesu budowania ani testów automatycznych. Przed wdrożeniem warto:
1. Sprawdzić składnię zmienionych plików:
```bash
php -l inc/classes/inContact/Shortcode.php
```
2. Po zmianach w tekstach zaktualizować `languages/in-contact.pot` i `.po`, a następnie skompilować `.mo`.
3. Ręcznie przetestować na stronie z shortcode'em:
- wysyłkę wiadomości zawierającej apostrofy, cudzysłowy i polskie znaki,
- komunikaty walidacji przy pustych polach,
- zapis ustawień w panelu.
Nowe klasy umieszczaj w `inc/classes/inContact/` w przestrzeni nazw `inContact` — autoloader załaduje je na podstawie nazwy.
+210 -1
View File
@@ -1 +1,210 @@
form #website{ display:none; } /* ============================================================
inContact — cform.css v0.3
Dark, modern, photography-focused form styles
Prefix: .ic- (inContact)
============================================================ */
/* ---------- Tokeny ---------- */
:root {
--ic-bg: #ffffff;
--ic-surface: #f8f8f8;
--ic-border: #dde0e8;
--ic-border-focus: #2563eb;
--ic-text: #1a1d26;
--ic-text-muted: #8a909e;
--ic-accent: #2563eb;
--ic-accent-dark: #1a4fc4;
--ic-error: #dc2626;
--ic-success-bg: #f0fdf4;
--ic-success-txt: #166534;
--ic-error-bg: #fef2f2;
--ic-radius: 6px;
--ic-transition: 200ms ease;
--ic-font: inherit;
}
/* ---------- Wrapper ---------- */
.ic-wrap {
max-width: 680px;
margin: 0 auto;
padding: 40px 48px;
background: var(--ic-surface);
border: 1px solid var(--ic-border);
border-radius: 10px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.07);
}
/* ---------- Alerty ---------- */
.ic-alert {
padding: 14px 18px;
border-radius: var(--ic-radius);
margin-bottom: 28px;
font-size: 0.92rem;
line-height: 1.5;
}
.ic-alert--success {
background: var(--ic-success-bg);
color: var(--ic-success-txt);
border: 1px solid #1e5e38;
}
.ic-alert--error {
background: var(--ic-error-bg);
color: var(--ic-error);
border: 1px solid #5e1e1e;
}
/* ---------- Pola formularza ---------- */
.ic-field {
margin-bottom: 22px;
position: relative;
}
/* Honeypot — ukryte */
.ic-field--honey {
position: absolute;
left: -9999px;
width: 1px;
height: 1px;
overflow: hidden;
opacity: 0;
}
.ic-field label {
display: block;
margin-bottom: 7px;
font-size: 0.82rem;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ic-text-muted);
}
.ic-field input[type="text"],
.ic-field input[type="email"],
.ic-field textarea {
display: block;
width: 100%;
padding: 12px 16px;
background: var(--ic-bg);
border: 1px solid var(--ic-border);
border-radius: var(--ic-radius);
color: var(--ic-text);
font-size: 1rem;
font-family: inherit;
line-height: 1.5;
transition:
border-color var(--ic-transition),
box-shadow var(--ic-transition);
box-sizing: border-box;
-webkit-appearance: none;
appearance: none;
}
.ic-field input::placeholder,
.ic-field textarea::placeholder {
color: var(--ic-text-muted);
opacity: 1;
}
.ic-field input:focus,
.ic-field textarea:focus {
outline: none;
border-color: var(--ic-border-focus);
box-shadow: 0 0 0 3px rgba(226, 176, 74, 0.15);
}
.ic-field textarea {
resize: vertical;
min-height: 130px;
}
/* ---------- Walidacja ---------- */
.ic-field__error {
display: none;
margin-top: 6px;
font-size: 0.8rem;
color: var(--ic-error);
}
.ic-field--invalid input,
.ic-field--invalid textarea {
border-color: var(--ic-error);
box-shadow: 0 0 0 3px rgba(224, 85, 85, 0.15);
}
.ic-field--invalid .ic-field__error {
display: block;
}
/* ---------- reCAPTCHA ---------- */
.ic-field--captcha {
margin-bottom: 26px;
}
/* reCAPTCHA ma własny iframe — filtrujemy tak żeby ciemne tło nie świeciło przez padding */
.ic-field--captcha .g-recaptcha {
display: inline-block;
border-radius: var(--ic-radius);
overflow: hidden;
}
/* ---------- Przycisk ---------- */
.ic-field--submit {
margin-top: 8px;
margin-bottom: 0;
}
#ic-submit {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 13px 32px;
background: var(--ic-accent);
color: #ffffff;
border: none;
border-radius: var(--ic-radius);
font-size: 0.95rem;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition:
background var(--ic-transition),
transform var(--ic-transition),
box-shadow var(--ic-transition);
-webkit-appearance: none;
appearance: none;
}
#ic-submit svg {
flex-shrink: 0;
transition: transform var(--ic-transition);
}
#ic-submit:hover {
background: var(--ic-accent-dark);
box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3);
transform: translateY(-1px);
}
#ic-submit:hover svg {
transform: translateX(2px) translateY(-2px);
}
#ic-submit:active {
transform: translateY(0);
box-shadow: none;
}
#ic-submit:focus-visible {
outline: 2px solid var(--ic-accent);
outline-offset: 3px;
}
/* ---------- Responsywność ---------- */
@media (max-width: 640px) {
.ic-wrap {
padding: 28px 20px;
}
}
+36 -70
View File
@@ -39,49 +39,35 @@ class AdminMenu
public function InContactSettings() public function InContactSettings()
{ {
$updated = isset($_POST["updated"]) ? $_POST["updated"] : ""; $nonce = isset($_POST["incontact-config"])
$incontactconfig = isset($_REQUEST["incontact-config"]) ? sanitize_text_field(wp_unslash($_POST["incontact-config"]))
? $_REQUEST["incontact-config"]
: ""; : "";
if ( if (
$updated === "true" || $_SERVER["REQUEST_METHOD"] === "POST" &&
wp_verify_nonce($incontactconfig, "incontact-update") current_user_can("manage_options") &&
wp_verify_nonce($nonce, "incontact-update")
) { ) {
$fields = [
update_option("incontact-site-key", $_POST["incontact-site-key"]); "incontact-site-key" => "sanitize_text_field",
update_option( "incontact-secret-key" => "sanitize_text_field",
"incontact-secret-key", "incontact-target-mail" => "sanitize_email",
$_POST["incontact-secret-key"], "incontact-form-ph-name" => "sanitize_text_field",
); "incontact-form-ph-email" => "sanitize_text_field",
update_option( "incontact-form-ph-message" => "sanitize_text_field",
"incontact-target-mail", "incontact-form-name" => "sanitize_text_field",
$_POST["incontact-target-mail"], "incontact-form-email" => "sanitize_text_field",
); "incontact-form-message" => "sanitize_text_field",
update_option( "incontact-form-snd-ok" => "sanitize_text_field",
"incontact-form-ph-name", ];
$_POST["incontact-form-ph-name"], foreach ($fields as $option => $sanitize) {
); if (!isset($_POST[$option])) {
update_option( continue;
"incontact-form-ph-email", }
$_POST["incontact-form-ph-email"], update_option(
); $option,
update_option( $sanitize(wp_unslash($_POST[$option])),
"incontact-form-ph-message", );
$_POST["incontact-form-ph-message"], }
);
update_option("incontact-form-name", $_POST["incontact-form-name"]);
update_option(
"incontact-form-email",
$_POST["incontact-form-email"],
);
update_option(
"incontact-form-message",
$_POST["incontact-form-message"],
);
update_option(
"incontact-form-snd-ok",
$_POST["incontact-form-snd-ok"],
);
?> ?>
<div class="updated"> <div class="updated">
@@ -108,9 +94,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-site-key" id="incontact-site-key" type="text" <td><input name="incontact-site-key" id="incontact-site-key" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-site-key")); ?>" class="regular-text"/></td>
"incontact-site-key",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-secret-key"><?php echo esc_html__( <th><label for="incontact-secret-key"><?php echo esc_html__(
@@ -118,9 +102,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-secret-key" id="incontact-secret-key" type="text" <td><input name="incontact-secret-key" id="incontact-secret-key" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-secret-key")); ?>" class="regular-text"/></td>
"incontact-secret-key",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-target-mail"><?php echo esc_html__( <th><label for="incontact-target-mail"><?php echo esc_html__(
@@ -128,9 +110,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-target-mail" id="incontact-target-mail" type="text" <td><input name="incontact-target-mail" id="incontact-target-mail" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-target-mail")); ?>" class="regular-text"/></td>
"incontact-target-mail",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
@@ -139,9 +119,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-ph-name" id="incontact-form-ph-name" type="text" <td><input name="incontact-form-ph-name" id="incontact-form-ph-name" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-ph-name")); ?>" class="regular-text"/></td>
"incontact-form-ph-name",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-form-ph-email"><?php echo esc_html__( <th><label for="incontact-form-ph-email"><?php echo esc_html__(
@@ -149,9 +127,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-ph-email" id="incontact-form-ph-email" type="text" <td><input name="incontact-form-ph-email" id="incontact-form-ph-email" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-ph-email")); ?>" class="regular-text"/></td>
"incontact-form-ph-email",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-form-ph-message"><?php echo esc_html__( <th><label for="incontact-form-ph-message"><?php echo esc_html__(
@@ -159,9 +135,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-ph-message" id="incontact-form-ph-message" type="text" <td><input name="incontact-form-ph-message" id="incontact-form-ph-message" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-ph-message")); ?>" class="regular-text"/></td>
"incontact-form-ph-message",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
@@ -170,9 +144,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-name" id="incontact-form-name" type="text" <td><input name="incontact-form-name" id="incontact-form-name" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-name")); ?>" class="regular-text"/></td>
"incontact-form-name",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-form-email"><?php echo esc_html__( <th><label for="incontact-form-email"><?php echo esc_html__(
@@ -180,9 +152,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-email" id="incontact-form-email" type="text" <td><input name="incontact-form-email" id="incontact-form-email" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-email")); ?>" class="regular-text"/></td>
"incontact-form-email",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
<th><label for="incontact-form-message"><?php echo esc_html__( <th><label for="incontact-form-message"><?php echo esc_html__(
@@ -190,9 +160,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-message" id="incontact-form-message" type="text" <td><input name="incontact-form-message" id="incontact-form-message" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-message")); ?>" class="regular-text"/></td>
"incontact-form-message",
); ?>" class="regular-text"/></td>
</tr> </tr>
<tr> <tr>
@@ -201,9 +169,7 @@ class AdminMenu
"in-contact", "in-contact",
); ?></label></th> ); ?></label></th>
<td><input name="incontact-form-snd-ok" id="incontact-form-snd-ok" type="text" <td><input name="incontact-form-snd-ok" id="incontact-form-snd-ok" type="text"
value="<?php echo get_option( value="<?php echo esc_attr(get_option("incontact-form-snd-ok")); ?>" class="regular-text"/></td>
"incontact-form-snd-ok",
); ?>" class="regular-text"/></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
+20 -14
View File
@@ -11,19 +11,25 @@ namespace inContact;
* @version 0.2 * @version 0.2
*/ */
class Enqueue { class Enqueue
{
use Singleton;
use Singleton; /*function __construct() {
function __construct() {
add_action('wp_enqueue_scripts',[ $this, 'enqueueScripts']); add_action('wp_enqueue_scripts',[ $this, 'enqueueScripts']);
} }*/
public function enqueueScripts() { public function enqueueScripts()
global $pluginDirUrl, $pluginPath; {
wp_register_style('ContactCss', $pluginDirUrl.'css/inContact.css', [], filemtime( $pluginPath . 'css/inContact.css'), 'all'); global $pluginDirUrl, $pluginPath;
wp_register_style(
wp_enqueue_style('ContactCss'); "ContactCss",
$pluginDirUrl . "css/inContact.css",
} [],
} filemtime($pluginPath . "css/inContact.css"),
"all",
);
wp_enqueue_style("ContactCss");
}
}
+233 -184
View File
@@ -3,12 +3,12 @@
namespace inContact; namespace inContact;
/** /**
* Klasa Menus * Klasa Shortcode
* *
* @link https://krzysztof-turek.com * @link https://krzysztof-turek.com
* *
* @package tylkofotografia.pl * @package tylkofotografia.pl
* @version 0.2 * @version 0.3
*/ */
class Shortcode class Shortcode
{ {
@@ -21,7 +21,7 @@ class Shortcode
protected function addShortcode(): void protected function addShortcode(): void
{ {
add_shortcode("in-contact", [$this, "inContact"]); add_shortcode("inContact", [$this, "inContact"]);
} }
public function inContact($atts) public function inContact($atts)
@@ -29,29 +29,34 @@ class Shortcode
$em_name = null; $em_name = null;
$em_mail = null; $em_mail = null;
$em_message = null; $em_message = null;
$class = null;
$html = null; $html = null;
$error = null; $error = null;
$body = null; $body = null;
$telefon = null; $telefon = null;
$mailResult = 0; $mailResult = 0;
$canSend = false;
$sendFailed = false;
$form_submitted = $_SERVER["REQUEST_METHOD"] === "POST"; $form_submitted = $_SERVER["REQUEST_METHOD"] === "POST";
if (!empty($_POST["website"])) { global $pluginDirUrl;
die();
} // Honeypot — bot dostaje pozorny sukces, mail nie jest wysyłany
$isBot = !empty($_POST["website"]);
if ($form_submitted) { if ($form_submitted) {
$emmsg = isset($_POST["emmsg"]) ? $_POST["emmsg"] : ""; $emmsg = isset($_POST["emmsg"]) ? $_POST["emmsg"] : "";
// Walidacja pól
if (!empty($_POST["em_name"])) { if (!empty($_POST["em_name"])) {
$em_name = $_POST["em_name"]; $em_name = sanitize_text_field(wp_unslash($_POST["em_name"]));
} else { } else {
$error .= $error .=
esc_html__("Please enter your name", "in-contact") . esc_html__("Please enter your name", "in-contact") .
"<br />"; "<br />";
} }
if (!empty($_POST["em_mail"])) { if (!empty($_POST["em_mail"]) && is_email($_POST["em_mail"])) {
$em_mail = $_POST["em_mail"]; $em_mail = sanitize_email(wp_unslash($_POST["em_mail"]));
} else { } else {
$error .= $error .=
esc_html__( esc_html__(
@@ -60,41 +65,47 @@ class Shortcode
) . "<br />"; ) . "<br />";
} }
if (!empty($_POST["em_message"])) { if (!empty($_POST["em_message"])) {
$em_message = $_POST["em_message"]; $em_message = sanitize_textarea_field(
wp_unslash($_POST["em_message"]),
);
} else { } else {
$error .= $error .=
esc_html__("Please enter your message", "in-contact") . esc_html__("Please enter your message", "in-contact") .
"<br />"; "<br />";
} }
$targetEmail = // Budowanie emaila
"To: Tylkofotografia <" . // From z domeny strony (SPF/DMARC), adres nadawcy tylko w Reply-To
get_option("incontact-target-mail") . $siteHost = (string) wp_parse_url(home_url(), PHP_URL_HOST);
">"; if (strpos($siteHost, "www.") === 0) {
$mailResult = 0; $siteHost = substr($siteHost, 4);
$headers = "MIME-Version: 1.0" . "\r\n"; }
$headers .= $headerChars = ["\"", "<", ">", "\r", "\n"];
"Content-type: text/html; charset=" . $fromName = str_replace(
get_bloginfo("charset") . $headerChars,
"" . "",
"\r\n"; wp_specialchars_decode(get_bloginfo("name"), ENT_QUOTES),
$headers .= "From: " . $em_name . " <" . $em_mail . ">" . "\r\n"; );
$replyName = str_replace($headerChars, "", (string) $em_name);
$headers = [ $headers = [
"Content-Type: text/html; charset=UTF-8", "Content-Type: text/html; charset=UTF-8",
"From: " . $em_name . " <" . $em_mail . ">", "From: " . $fromName . " <wordpress@" . $siteHost . ">",
"Reply-To: " . $em_name . " <" . $em_mail . ">", "Reply-To: " . $replyName . " <" . $em_mail . ">",
]; ];
$targetEmail = get_option("incontact-target-mail");
$emailTitle = __("New message from contact form", "in-contact"); $emailTitle = __("New message from contact form", "in-contact");
$emailHeading = __("Contact details", "in-contact"); $emailHeading = __("Contact details", "in-contact");
$emailNameLabel = __("Name and surname", "in-contact"); $emailNameLabel = __("Name and surname", "in-contact");
$emailEmailLabel = __("Email", "in-contact"); $emailEmailLabel = __("Email", "in-contact");
$emailMessageHeading = __("Message content", "in-contact"); $emailMsgHeading = __("Message content", "in-contact");
$emailReplyLabel = __("Reply to message", "in-contact"); $emailReplyLabel = __("Reply to message", "in-contact");
$emailFooter = __( $emailFooter = __(
"This email was generated automatically by the website contact form.", "This email was generated automatically by the website contact form.",
"in-contact", "in-contact",
); );
$emailRights = __("All rights reserved.", "in-contact"); $emailRights = __("All rights reserved.", "in-contact");
$body = $body =
'<!DOCTYPE html> '<!DOCTYPE html>
<html lang="pl"> <html lang="pl">
@@ -104,70 +115,24 @@ class Shortcode
esc_html($emailTitle) . esc_html($emailTitle) .
'</title> '</title>
<style> <style>
body { body { font-family: Arial, sans-serif; background-color: #f5f5f5; margin: 0; padding: 0; }
font-family: Arial, sans-serif; .container { width: 90%; max-width: 600px; margin: 20px auto; background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 0 10px rgba(0,0,0,.1); }
background-color: #f5f5f5; .header { background-color: #1a1a2e; color: #ffffff; padding: 20px; text-align: center; }
margin: 0; .header h1 { margin: 0; font-size: 20px; }
padding: 0; .content { padding: 24px; line-height: 1.6; }
} .content h2 { margin-top: 0; color: #1a1a2e; }
.container { .info { background-color: #f9f9f9; border-left: 4px solid #e2b04a; padding: 12px 16px; margin: 16px 0; border-radius: 0 4px 4px 0; }
width: 90%; .info h3 { margin: 0 0 8px; color: #1a1a2e; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
max-width: 600px; .button { display: inline-block; padding: 10px 20px; margin-top: 20px; background-color: #e2b04a; color: #1a1a2e; text-decoration: none; border-radius: 4px; font-weight: bold; }
margin: 20px auto; .footer { background-color: #f1f1f1; text-align: center; padding: 12px; font-size: 12px; color: #777; }
background-color: #ffffff; @media (max-width: 600px) { .container { width: 95%; } }
border-radius: 8px;
overflow: hidden;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.header {
background-color: #3a7bd5;
color: #ffffff;
padding: 20px;
text-align: center;
}
.content {
padding: 20px;
line-height: 1.6;
}
.content h2 {
margin-top: 0;
}
.footer {
background-color: #f1f1f1;
text-align: center;
padding: 10px;
font-size: 12px;
color: #777777;
}
.button {
display: inline-block;
padding: 10px 20px;
margin-top: 20px;
background-color: #3a7bd5;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
}
.info {
background-color: #f9f9f9;
border-left: 4px solid #3a7bd5;
padding: 10px;
margin: 10px 0;
}
@media (max-width: 600px) {
.container {
width: 95%;
}
}
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<div class="header"> <div class="header"><h1>' .
<h1>' .
esc_html($emailTitle) . esc_html($emailTitle) .
'</h1> '</h1></div>
</div>
<div class="content"> <div class="content">
<h2>' . <h2>' .
esc_html($emailHeading) . esc_html($emailHeading) .
@@ -178,15 +143,12 @@ class Shortcode
<p><strong>' . <p><strong>' .
esc_html($emailEmailLabel) . esc_html($emailEmailLabel) .
':</strong> {{EMAIL}}</p> ':</strong> {{EMAIL}}</p>
<div class="info"> <div class="info">
<h3>' . <h3>' .
esc_html($emailMessageHeading) . esc_html($emailMsgHeading) .
':</h3> '</h3>
<p>{{WIADOMOSC}}</p> <p>{{WIADOMOSC}}</p>
</div> </div>
<a href="mailto:{{EMAIL}}" class="button">' . <a href="mailto:{{EMAIL}}" class="button">' .
esc_html($emailReplyLabel) . esc_html($emailReplyLabel) .
'</a> '</a>
@@ -195,14 +157,16 @@ class Shortcode
' . ' .
esc_html($emailFooter) . esc_html($emailFooter) .
'<br> '<br>
© {{ROK}} Twoja Firma. ' . &copy; {{ROK}} ' .
esc_html(get_bloginfo("name")) .
". " .
esc_html($emailRights) . esc_html($emailRights) .
' '
</div> </div>
</div> </div>
</body> </body>
</html> </html>';
';
$body = str_replace( $body = str_replace(
[ [
"{{IMIE_NAZWISKO}}", "{{IMIE_NAZWISKO}}",
@@ -212,35 +176,44 @@ class Shortcode
"{{ROK}}", "{{ROK}}",
], ],
[ [
$em_name, esc_html($em_name),
$em_mail, esc_html($em_mail),
$telefon, esc_html($telefon),
str_replace(["\r\n", "\r", "\n"], "<br />", $em_message), str_replace(
["\r\n", "\r", "\n"],
"<br />",
esc_html($em_message),
),
date("Y"), date("Y"),
], ],
$body, $body,
); );
$gRecaptchaResponse = isset($_POST["g-recaptcha-response"])
? $_POST["g-recaptcha-response"]
: "";
// Obsługa błędów walidacji
if (!empty($error)) { if (!empty($error)) {
$html .= $html .=
'<div class="alert alert-success" role="alert">' . '<div class="ic-alert ic-alert--error">' .
$error . $error .
"</div>"; "</div>";
} elseif ($emmsg == "true") { } elseif ($isBot) {
$secret = get_option("incontact-secret-key"); $mailResult = 1;
$response = null; } elseif ($emmsg === "true") {
if (get_option("incontact-site-key") != "") { // reCAPTCHA
$gRecaptchaResponse = isset($_POST["g-recaptcha-response"])
? $_POST["g-recaptcha-response"]
: "";
$siteKey = get_option("incontact-site-key");
if ($siteKey != "") {
$secret = get_option("incontact-secret-key");
$reCaptcha = new \ReCaptcha\ReCaptcha($secret); $reCaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $reCaptcha $resp = $reCaptcha
->setExpectedHostname($_SERVER["SERVER_NAME"]) ->setExpectedHostname($_SERVER["SERVER_NAME"])
->setExpectedAction("submit")
->setScoreThreshold(0.5)
->verify($gRecaptchaResponse, $_SERVER["REMOTE_ADDR"]); ->verify($gRecaptchaResponse, $_SERVER["REMOTE_ADDR"]);
if ($resp->isSuccess()) { if ($resp->isSuccess()) {
$canSend = true; $canSend = true;
} else {
$errors = $resp->getErrorCodes();
} }
} else { } else {
$canSend = true; $canSend = true;
@@ -254,98 +227,174 @@ class Shortcode
$headers, $headers,
); );
} }
$sendFailed = !$mailResult;
} }
} }
wp_enqueue_style("ContactCss", plugins_url("/css/cform.css", __FILE__));
if (get_option("incontact-site-key") != "") { // Enqueue styles & reCAPTCHA
$html .= wp_enqueue_style(
'<script src="https://www.google.com/recaptcha/api.js"></script> "inContactCss",
<script> $pluginDirUrl . "css/inContact.css?v=12",
$(document).ready(function(){window.setTimeout(function(){$(".alert").fadeTo(500,0).slideUp(500,function(){$(this).remove()})},2e3)}),$(document).ready(function(){"use strict";window.addEventListener("load",function(){var t=document.getElementsByClassName("needs-validation");Array.prototype.filter.call(t,function(t){t.addEventListener("submit",function(e){!1===t.checkValidity()&&(e.preventDefault(),e.stopPropagation()),t.classList.add("was-validated")},!1)})},!1)})(); [],
</script>' . "\n"; "0.3",
);
$siteKey = get_option("incontact-site-key");
if ($siteKey != "") {
wp_enqueue_script(
"recaptcha",
"https://www.google.com/recaptcha/api.js?render=" . $siteKey,
[],
null,
true,
);
wp_add_inline_script(
"recaptcha",
"
document.getElementById('ic-form').addEventListener('submit', function(e) {
if (e.defaultPrevented) return;
var token = document.getElementById('g-recaptcha-response').value;
if (!token) {
e.preventDefault();
grecaptcha.ready(function() {
grecaptcha.execute('" .
esc_js($siteKey) .
"', {action: 'submit'})
.then(function(token) {
document.getElementById('g-recaptcha-response').value = token;
document.getElementById('ic-form').submit();
});
});
}
});
",
);
} }
$html .= '<div class="row justify-content-md-center"> // Budowanie HTML formularza
<div class="col-12">'; $html .= '<div class="ic-wrap">';
if ($mailResult == 1) { if ($mailResult == 1) {
$html .= $html .=
'<div class="alert alert-success" role="alert">' . '<div class="ic-alert ic-alert--success">' .
get_option("incontact-form-snd-ok") . esc_html(get_option("incontact-form-snd-ok")) .
"</div>";
} elseif ($sendFailed) {
$html .=
'<div class="ic-alert ic-alert--error">' .
esc_html__(
"The message could not be sent. Please try again.",
"in-contact",
) .
"</div>"; "</div>";
} }
// Po nieudanej próbie pola zachowują wpisane wartości
$keep = $form_submitted && $mailResult != 1;
$valName = $keep ? esc_attr((string) $em_name) : "";
$valMail = $keep ? esc_attr((string) $em_mail) : "";
$valMessage = $keep ? esc_textarea((string) $em_message) : "";
$html .= '<form action="" method="post" id="ic-form" novalidate>';
$html .= $html .=
'<div class="jumbotron"><form action="" class="needs-validation" novalidate method="post" id="demo-form"> '<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response">';
<input type="hidden" name="emmsg" value="true" /> $html .= '<input type="hidden" name="emmsg" value="true" />';
<input type="text" id="website" name="website" />
<div class="jumbotron"> // Honeypot — ukryte pole
<div class="form-group"> $html .=
<label for="name" class="col-2 control-label">' . '<div class="ic-field ic-field--honey" aria-hidden="true">' .
get_option("incontact-form-name") . '<input type="text" id="website" name="website" tabindex="-1" autocomplete="off" />' .
'</label> "</div>";
<div class="col-12">
<input type="text" class="form-control" id="name" name="em_name" placeholder="' . // Pole: Nazwa
get_option("incontact-form-ph-name") . $html .=
'" value="" required> '<div class="ic-field">' .
<div class="invalid-feedback"> '<label for="ic-name">' .
' . esc_html(get_option("incontact-form-name")) .
"</label>" .
'<input type="text" id="ic-name" name="em_name" value="' .
$valName .
'" placeholder="' .
esc_attr(get_option("incontact-form-ph-name")) .
'" required />' .
'<span class="ic-field__error">' .
esc_html__("Please enter your name!", "in-contact") . esc_html__("Please enter your name!", "in-contact") .
' "</span>" .
</div> "</div>";
</div>
</div> // Pole: Email
<div class="form-group"> $html .=
<label for="email" class="col-2 control-label">' . '<div class="ic-field">' .
get_option("incontact-form-email") . '<label for="ic-email">' .
'</label> esc_html(get_option("incontact-form-email")) .
<div class="col-12"> "</label>" .
<input type="email" class="form-control" id="email" name="em_mail" placeholder="' . '<input type="email" id="ic-email" name="em_mail" value="' .
get_option("incontact-form-ph-email") . $valMail .
'" value="" required> '" placeholder="' .
<div class="invalid-feedback"> esc_attr(get_option("incontact-form-ph-email")) .
' . '" required />' .
'<span class="ic-field__error">' .
esc_html__("Please enter your email address!", "in-contact") . esc_html__("Please enter your email address!", "in-contact") .
' "</span>" .
</div> "</div>";
</div>
</div> // Pole: Wiadomość
<div class="form-group"> $html .=
<p class="col-2 control-label">' . '<div class="ic-field">' .
get_option("incontact-form-message") . '<label for="ic-message">' .
'</p> esc_html(get_option("incontact-form-message")) .
<div class="col-12"> "</label>" .
<textarea class="form-control" rows="4" name="em_message" placeholder="' . '<textarea id="ic-message" name="em_message" rows="5" placeholder="' .
get_option("incontact-form-ph-message") . esc_attr(get_option("incontact-form-ph-message")) .
'" required></textarea> '" required>' .
<div class="invalid-feedback"> $valMessage .
' . '</textarea>' .
'<span class="ic-field__error">' .
esc_html__("Please enter your message!", "in-contact") . esc_html__("Please enter your message!", "in-contact") .
' "</span>" .
</div> "</div>";
</div>
</div> // Przycisk
<div class="form-group"> $html .=
<div class="col-4"> '<div class="ic-field ic-field--submit">' .
<div class="g-recaptcha" data-sitekey="' . '<button type="submit" id="ic-submit">' .
get_option("incontact-site-key") . '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>' .
'"></div> " " .
</div>
</div>
<div class="form-group">
<p></p>
<div class="col-4">
<button id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
<i class="fas fa-paper-plane"></i> ' .
esc_html__("Send", "in-contact") . esc_html__("Send", "in-contact") .
' "</button>" .
</button> "</div>";
</div>
</div> $html .= "</form>";
</div> $html .= "</div>"; // .ic-wrap
</form>
</div> // Inline JS — walidacja bez Bootstrap
</div></div>'; $html .= "<script>
(function(){
var form = document.getElementById('ic-form');
if (!form) return;
form.addEventListener('submit', function(e) {
var valid = true;
form.querySelectorAll('[required]').forEach(function(field) {
var wrapper = field.closest('.ic-field');
if (!field.value.trim()) {
wrapper.classList.add('ic-field--invalid');
valid = false;
} else {
wrapper.classList.remove('ic-field--invalid');
}
});
if (!valid) e.preventDefault();
});
form.querySelectorAll('[required]').forEach(function(field) {
field.addEventListener('input', function() {
if (field.value.trim()) {
field.closest('.ic-field').classList.remove('ic-field--invalid');
}
});
});
})();
</script>";
return $html; return $html;
} }
Binary file not shown.
+4
View File
@@ -131,3 +131,7 @@ msgstr "Podaj swoją wiadomość!"
#: inc/classes/inContact/Shortcode.php #: inc/classes/inContact/Shortcode.php
msgid "Send" msgid "Send"
msgstr "Wyślij" msgstr "Wyślij"
#: inc/classes/inContact/Shortcode.php
msgid "The message could not be sent. Please try again."
msgstr "Nie udało się wysłać wiadomości. Spróbuj ponownie."
+4
View File
@@ -130,3 +130,7 @@ msgstr ""
#: inc/classes/inContact/Shortcode.php #: inc/classes/inContact/Shortcode.php
msgid "Send" msgid "Send"
msgstr "" msgstr ""
#: inc/classes/inContact/Shortcode.php
msgid "The message could not be sent. Please try again."
msgstr ""