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:
- How to fix ‘Notice: Undefined index:’ in PHP form action
- What is PHPSESSID?
- Setting custom cookies in WordPress
- How to stop form resubmission on page refresh
- How to correctly submit a search form and display the result in an independent page
- add_filter the_content str_replace after shortcode
- Genesis – Customize search form
- How to set custom cookies before output
- Metabox repeating fields – radio buttons not saving correctly
- Check if user already visited this post today
- Display message once per session to users with a specific role
- How to exclude pages from the search results
- How to insert PHP code in a WordPress Post
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- How to handle a custom form in wordpress to submit to another page?
- Has anyone tried putting PHP ActiveRecord on WordPress?
- Handling error states with admin_post
- Creating wordpress user registration form
- Using Cookie Data For WP_Query Loop
- Creating a WordPress form with a PHP script and default header
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- submit the form to same page
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- How to resolve error “Cookies are blocked due to unexpected output.”?
- Using a nonce in a Custom Login Form
- Submitting form via admin-post.php and handling errors
- Implement a multi-value input field where the number of entries is not limited
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Passing POST data from one WP post to another
- Getting the dropdown menu to redirect to different pages?
- Processing a subscription form with POST method?
- 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
- Using Multiple Submit buttons to trigger customised php functions
- Get Admin Email Address From External PHP page
- Adding Custom Forms
- How do I let users upload files to a chosen location?
- woocommerce registration form with klaviyo(don’t work with current user)
- Setting a cookie upon specific URL visit
- How to Highlight unread WordPress posts?
- How to create a form and display its content as table in admin panel?
- Custom Form Processing Issue
- My form action url is being prepended with a directory that does not exists
- Custom profile field with birthday. Troubles with
- 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 combine wordpress_logged_in cookies in one cookie?
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to store data from multiple forms using ajax and php
- How to use $query->set with post__in?
- Ajax loaded form replaces form action with Ajax url
- Trying to display user meta by “name” – not by “ID”
- Styling admin page rows in order of importance (checkboxes)
- How to set a cookie based on a page Get variable?
- Headers for Contact Form are wrong
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- Display default WordPress login/registration form into a modal window
- Using Nonce for my Form
- Trouble using wordpress functions in a pop-up modal form
- Force string into signup form
- custom contact form no longer working (because of 3.2?)
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- Correct Syntax for uploading files to custom directory in WordPress
- ajax form function error
- How to pass username into form that sends data to database
- HOW TO Insert Existing PHP Code to WOrdPress
- Send foreach $_post method to contact form 7 [closed]
- Cookie not created in AJAX request
- php inside HTML via shortcode? [closed]
- Where to put include php file?
- Use HTML Form Data in PHP Function – WordPress Admin Page
- Why can’t I enter the wordpress admin interface?
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- Contact form with dynamic dropdown and filter
- Keep users logged in Without Remember Me
- Why can’t I enter the wordpress admin interface?
- Redirect loop upon installation of my plugin
- Field validation strlen works in php7.4 fails 8.1 [closed]
- Custom form that stores data in mysql database
- Embed PHP script into WP – what is the best way
- Preventing script injections in HTML form
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”
- Putting form result in my database
- Bulk data save in custom table
- Can’t insert into a database wordpress
- Can’t set a cookie from php
- Help with commenting system
- Display endpoint’s return into a file (file_put_contents())
- How to create a form that display license key (and email it to user) after the user enter their email and 10 digit code?
- Quiz page template, checked attribute missing when option selected
- Send summary email from a form with wp_mail
- Validate a custom form with js and php
- Automatically populating a date parameter within a shortcode
- Custom PHP contact form issue
- Trouble getting wpdb to work – first time
- How can I process a form submission from an HTTP POST request?