You use setcookie() like any other function, with parameters as described in the Codex.
How you would use it in a form would usually depend on how and when the $_COOKIE variable needs to be made accessible.
One common method, if you want a change in the DOM both to register immediately and to persist, is to use a Javascript/jQuery function whose effect is duplicated in the PHP functions that will draw upon $_COOKIE variables. The cookie will also typically be set or updated in the same script, commonly with the aid of jquery-cookie or js-cookie.
Related Posts:
- What is PHPSESSID?
- Setting custom cookies in WordPress
- How to stop form resubmission on page refresh
- add_filter the_content str_replace after shortcode
- How to insert PHP code in a WordPress Post
- Has anyone tried putting PHP ActiveRecord on WordPress?
- Handling error states with admin_post
- Creating wordpress user registration form
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- Passing POST data from one WP post to another
- How to group 2 radio buttons in a widget?
- Ajax form submit within a Post Metabox
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- How to sanitize my cookie name
- Upload Image in a WordPress page using PHP
- Get Admin Email Address From External PHP page
- How to create a form and display its content as table in admin panel?
- My form action url is being prepended with a directory that does not exists
- Why is my cookie not unsetting upon logout? [closed]
- How can I reuse the code to capture a param in a URL and place in a value in a hidden form?
- How to store post ID’s in cookie or session to display the same posts later
- how can i use $_COOKIE[] + PostID to execute the below code?
- Post + form + action + results on the same page
- How to pre populate a form field with a link of a current user’s author profile?
- Why Won’t My Inputs in a form with a Get method work together?
- iframe does not store session/cookie when refresh parent
- How to get the value of input hidden html from text editor to custom page template?
- Show success or error messages in Ajax response to WordPress custom registration form
- Contact form won’t submit
- wp_mail file attachment not being placed in upload folder?
- Insert custom PHP head above in WP pages
- Form Security: nonce vs. jQuery
- Trying do build a contact form
- How to execute html code inside php?
- My php code is not being executed
- Can a page contain php code?
- How to send form data from WordPress (Meta Box) to an OData service?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- $_SESSION variable not saving on page refresh or new page
- Why does my user not get added to the database on custom registration?
- How to add post meta in while loop?
- PHP Contact form
- Get wp_current_user_id using PHP and MySQL
- PHP- Why is my contact form keep showing it is invalid? [closed]
- Simple php in wordpress widget [closed]
- Pass important values server-side when processing form
- Adding data to custom wordpress database table
- Make a page (url) not cacheable [closed]
- Display multi-select box choices in a bullet list [closed]
- Custom forms with HTML
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Triggering a timewall after X days
- $_POST returning empty values
- Trying to update Woocommerce meta values
- How to send custom form submissions to WordPress Database?
- Custom PHP form needs refresh to load page correctly
- I want it to detect the duplicate comment and give a warning on the same page
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- IF statement not working – Any suggestions?
- Confuse between forms and tables
- wordpress contact form messages not sending although it saying they were sent successfully with this php code
- Using a PHP form, get the page title or any other element in the sent e-mail
- Use WP user status (logged_in) to manage access to independent application
- custom search query database in child theme
- Creating a WordPress addon for ContactForm7 submission (.XML file export)
- Using transients to store form notifications
- Insert data from form to database
- WordPress load javascript file if something… (after the page is loaded)
- not able to access $_POST on backend profile update
- Serve cookie free URLs in WordPress without using a CDN
- Custom Plugin Develoment, Form Action
- wordpress form action page not found
- Trouble with checked() for array of multiple checkboxes
- Custom HTML form using PHP – help with ajax/username validation
- Form direction to .php on localhost
- Form not working as it should in WordPress, but in a normal HTML site it does
- Ajax call URL 404’ing when pushed to staging server
- Update only some custom user fields
- Passed variable gets undefined variable error on insert on next page
- How to set up an auto delete post?
- Dynamic form variables for post meta
- Trying to display user meta by “name” – not by “ID”
- How to set a cookie based on a page Get variable?
- Headers for Contact Form are wrong
- Using Nonce for my Form
- Trouble using wordpress functions in a pop-up modal form
- custom contact form no longer working (because of 3.2?)
- Correct Syntax for uploading files to custom directory in WordPress
- HOW TO Insert Existing PHP Code to WOrdPress
- Cookie not created in AJAX request
- php inside HTML via shortcode? [closed]
- Where to put include php file?
- Keep users logged in Without Remember Me
- Redirect loop upon installation of my plugin
- Field validation strlen works in php7.4 fails 8.1 [closed]
- Embed PHP script into WP – what is the best way
- Preventing script injections in HTML form
- Can’t insert into a database wordpress
- Help with commenting system
- Automatically populating a date parameter within a shortcode