WordPress.org

Ready to get started?Download WordPress

Forums

Form handling with WordPress - How to? (3 posts)

  1. converting2wp
    Member
    Posted 4 years ago #

    I've been using WordPress for quite awhile, but when I've needed form handling I've either

    o Used a form plugin that gathers the data and simply forwards it e-mail
    or
    o Coded a form and its action page outside of the WordPress environment (and kludged the theme)

    I'd like to figure out the "right" way to do this, but am having trouble finding documentation on this.

    What I'd like to do is have

    1. Page 1 has a form that collects some information
    2. Page 2 displays that information and customizes other content based on that info

    If I use a plugin, e.g. Contact Form 7, I can see how to save the data from the first page, but I can't figure out what token the two pages have in common so I can retrieve the data reliably in code on Page 2. Is there such a variable in WordPress that identifies the "session"?

    Or is the "right" way to code a PHP file for Page 1's form action so that the $_REQUEST is available directly (giving up the benefits of the form plugin)?

    I'm open to suggestions -- have tried cookies and global variables without success, but can revisit things if anyone can give me pointers on a "good" strategy. Or am I just not using the right plugin? [Had also tried Cforms II but was having difficulties that sent me to Contact Form 7.]

    Thanks.

  2. converting2wp
    Member
    Posted 4 years ago #

    Here's the path I'm going down for now. If anyone has a better suggestion, I'd be glad to hear about it:

    Set up the $posted_data array

    $myformdata=serialize($posted_data);
    setcookie ('myformdata',$myformdata,0,'/',$_SERVER['HTTP_HOST'],false,true);

    Then to retrieve the data

    $posted_data=unserialize(stripslashes($_COOKIE['myformdata']));

  3. converting2wp
    Member
    Posted 4 years ago #

    The third parameter there is the expiration time of the cookie and it should obviously be something other than "0". Sorry for copying in test code.

Topic Closed

This topic has been closed to new replies.

About this Topic