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?
- Genesis – Customize search form
- How to set custom cookies before output
- Check if user already visited this post today
- Display message once per session to users with a specific role
- 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
- Using Cookie Data For WP_Query Loop
- On update to 3.04 site started recording accents as “á” and “á”, what to do?
- submit the form to same page
- How to resolve error “Cookies are blocked due to unexpected output.”?
- Implement a multi-value input field where the number of entries is not limited
- 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
- woocommerce registration form with klaviyo(don’t work with current user)
- Setting a cookie upon specific URL visit
- How to Highlight unread WordPress posts?
- 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 to combine wordpress_logged_in cookies in one cookie?
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Custom search results page not working with empty search
- 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
- Why Won’t My Inputs in a form with a Get method work together?
- iframe does not store session/cookie when refresh parent
- Input data from email form not going to JSON file
- How to get the value of input hidden html from text editor to custom page template?
- Contact form won’t submit
- Search Query: how to construct a search string from two select elements?
- Databases – Submitting data from inputs to database [closed]
- How to show a ‘correct’ message after submit a form?
- db converts decimal number wrong
- Ajax contact form return 0
- “operation successful” message
- User register hook is not working in woocomerce register form
- Search WordPress using static html page
- How to put a form with php code into a variable or shortcode?
- How to send form data from WordPress (Meta Box) to an OData service?
- WordPress shortcode returns the data before
- Shortcode to embed Edit Account form not working
- Form Submission Not Working In Custom Theme
- Capture form data in one function and use it in another function (same file)
- Why does my user not get added to the database on custom registration?
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- form built dynamically with php, not submitting
- How to make a cookie be on the whole site instead of being on a specific page/
- Search only working on front page (index) , not working on other pages
- Pass important values server-side when processing form
- WPDB secure custom form
- Adding attribute to the post.php form tag in wp-admin
- How to make blog post entries appear as input form instead of just text?
- Set cookie for visitor
- Front end file upload returning wrong attachment url
- setcookies and header send
- WordPressUser Submission Form
- Page Options Saving But Not Updating In Backend
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- Cascading dropdown select search based on Parent Page & Child Page
- Triggering a timewall after X days
- Set cookie parameters on wp site – PHP not working?
- HTML Form Question
- Fatal error login WordPress [duplicate]
- I want it to detect the duplicate comment and give a warning on the same page
- Updating user meta adds string count to value?
- PHP multiple forms, same page, isset($_POST[]) not working?
- “Class Not Found” in HTML Form Target PHP File that contains the class
- Store user form submitted information in post type
- Implement jQuery Smart wizard
- Javascript / PHP – closing the loop
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- Updating the database after parsing CSV document
- Creating wordpress user registration form
- If input field has value Require another field – PHP
- Submitting my form to the database and then redirecting to payment site
- Passing link parameter values to form
- Processing forms with php to wordpress database
- Post from front end form to post_meta
- Accessing values entered via form – try again
- Nonce fail after second submit attempt
- Use WP_Query Data In Cookie
- Styling admin page rows in order of importance (checkboxes)
- How to set a cookie based on a page Get variable?
- Create and update Custom Cookie based on multiple GET and POST Values for first time visitors?
- Using Nonce for my Form
- Data inserted in database, but ajax calls error function
- upload images on front by user using form
- How to pass username into form that sends data to database
- Custom form that stores data in mysql database
- Putting form result in my database