=== FormCraft - Pre Populate Fields Add-On ===
Contributors: saptarshighosh
Tags: formcraft, forms, pre-populate, default values, dynamic fields
Requires at least: 5.0
Tested up to: 6.8
Requires PHP: 7.0
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Set default or dynamic values in your FormCraft forms when users see them.

== Description ==

An add-on for FormCraft 3 that fills form fields when the form loads. You can use:

1. **Default values**: while editing the form, type the value you want straight into the field on the form. The add-on saves it with the form.
2. **User data**: type a tag like `[User: display_name]` into a field. Logged-in users see their own data; visitors see an empty field.
   Tags: `[User: ID]`, `[User: user_login]`, `[User: user_email]`, `[User: user_url]`, `[User: user_registered]`, `[User: display_name]`, `[User: first_name]`, `[User: last_name]`, `[User: nickname]`. Any other user meta key works too, but keys that look like passwords, tokens or secrets are always blocked.
3. **URL parameters**: open the form with field IDs in the URL, e.g. `https://example.com/form-view/5?field1=12345`. You can see a field's ID by clicking the field in the builder (shown as FIELD1, FIELD2, ...). For checkboxes, separate several options with `||` (`field3=Red||Blue`). URL values replace any defaults. You can switch this off per form under Addons → Pre Populate Fields.
4. **Post data**: type a tag like `[Post: post_title]` into a field. It is filled from the post or page that shows the form.
   Tags: `[Post: ID]`, `[Post: url]`, `[Post: post_date]`, `[Post: post_title]`, `[Post: post_status]`, `[Post: post_name]`. You can also use the post's custom fields: `[Post: custom_field_name]`, e.g. `[Post: _price]` for a WooCommerce product.

Tags also work in **Hidden Field values**, text blocks, headings, labels and placeholders. One field can mix text and several tags, e.g. `Order for [User: first_name] [User: last_name]`.

Precedence (lowest to highest): builder default / tags → visitor's saved progress (if "Save Form Progress" is on) → URL parameters.

== Installation ==

1. Install and activate FormCraft 3.
2. Upload `formcraft-pre-populate` to `/wp-content/plugins/` (or upload the zip in Plugins → Add New → Upload Plugin) and activate it.
3. Open a form in the FormCraft builder. **Pre Populate Fields** appears under **Addons → Installed**. It lists the saved default values and the available tags (click a tag to copy it).
4. Type values or tags into the fields on the form, then click **Save**.

== Frequently Asked Questions ==

= How do I remove a default value? =
Clear the field on the form in the builder, or click × next to it in the add-on panel. Then save.

= Which post do [Post: ...] tags read from? =
The post or page that shows the form, including a form placed in a sidebar of a single post. To use a specific post, add `post_id` to the shortcode: `[fc id='5' post_id='123']`. On FormCraft's own form page (`/form-view/5`) there is no post, so post tags are empty.

= Does it work with page caching? =
URL parameters are applied in the browser, so they work on cached pages. User tags are resolved on the server, so exclude pages that use `[User: ...]` tags from your page cache. Otherwise one visitor could see another visitor's details.

= Which field types are supported? =
Default values typed in the builder: single-line text, email, paragraph, date, dropdown, checkbox and multiple choice. URL parameters also work for sliders and time pickers.

== Developer hooks ==

* `fcpp_prepopulate_data` (filter): `( array $data, int $form_id, array $meta, array $context )`. Final field ⇒ value map.
* `fcpp_user_value` (filter): `( mixed $value, string $key )`.
* `fcpp_post_value` (filter): `( mixed $value, string $key, int $post_id )`.
* `fcpp_context_post_id` (filter): `( int $post_id, array $shortcode_atts )`.
* `fcpp_blocked_keys` (filter): `( array $keys, string $type )`. Meta keys that are never exposed.

== Changelog ==

= 1.0.0 =
* Initial release: builder default values, [User: key] and [Post: key] tags (including custom fields), URL parameters, and tags in hidden fields and form text.
