WordPress.org

Ready to get started?Download WordPress

Forums

Conditional page (3 posts)

  1. thom667
    Member
    Posted 5 years ago #

    Hi.

    I basically removed the default sidebar.php code and wrote my own, which resides in /wordpress/wp-content/themes/starkers/sidebar.php

    Now, in the sidebar, I have a mailing list form whose 'action' file is called mlist.php which resides in /wordpress/mlist.php

    i.e. <form action="/wordpress/mlist.php" method="post">...

    mlist.php takes the email address address inputted and decides whether or not to add it to a database and then gives appropriate output. But I want this output to blend in with my theme.

    So say I create a page:

    <?php
    get_header();
    //CONDITIONAL STUFF GOES HERE
    get_sidebar();
    get_footer();
    ?>

    I want mlist.php do the following

    if (email address successfully added)
    {
      output success message;
    }
    else
    {
      output error message;
    }

    But I want the messages to appear where "//CONDITIONAL STUFF GOES HERE" is above. I tried creating separate php pages and then using header() to redirect but something went wrong. For example, I created the file /wordpress/wp-content/themes/starkers/invalid_email.php and used the following redirect code in mlist.php:

    header ("Location: ".TEMPLATEPATH."/invalid_email.php);

    But this didn't work and said that http://127.0.0.1/usr/var/www/.../starkers/invalid_email.php didn't exist. So obviously I don't understand how wordpress structures these redirects.

    Another thing, is that creating a page for each output message seems like overkill for me. Is there a neater way to do what I want?

    Sorry for the long post, thanks for reading.

  2. thom667
    Member
    Posted 5 years ago #

    OK, thought I'd just encompass it all into mlist.php.

    mlist.php:

    <?php
    
    get_header();
    
    // Email validation
    // and database queries
    // go here,
    // along with conditional output
    
    get_sidebar ();
    get_footer ();

    Now since I'm calling the get_*() functions, I'll need to move mlist.php into the theme folder, yes? Well that's what I did.

    Then I opened up sidebar.php and changed my form to <form action="mlist.php" method="post"> since mlist.php and sidebar.php reside in the same directory.
    This gave me an error when I submitted the form on my front page. So I changed it to action="full/path/to/mlist.php". Now I get an error "Call to undefined function get_header()". How do I get this to work?

  3. thom667
    Member
    Posted 5 years ago #

    Solved.

    Had to include wp-load.php.

Topic Closed

This topic has been closed to new replies.

About this Topic