Results 1 to 6 of 6

Thread: PHP Help #2

  1. #1
    Join Date
    Nov 2007
    Location
    MT
    Posts
    889

    PHP Help #2

    My last attempt to make this thread appears to have borked itself...

    http://www.tetongravity.com/forums/s...30393-PHP-Help

    so I'll try again. As before, if this is the wrong forum feel free to jong me in the right direction.

    I'm looking for someone who knows PHP code better than me (read: at all) to help figure out this code I'm trying to implement on my wordpress installation. The goal of the code is to create a password field which, when a password is entered, will load the page with the matching password. The passwords on the pages are created with the default wordpress password protection tool. here's the html for the password form:

    HTML Code:
    <form method="post" action="">
        <input type="password" name="passwordfield">
        <input type="hidden" name="homepagepassword" value="1">
        <input type="submit" value="Submit">
    </form>
    and the PHP which is living in my functions.php file:

    PHP Code:
    if(isset($_POST['homepagepassword'])){
        
    $post_password $_POST['passwordfield'];
        
    $post_id $wpdb->get_var$wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %d"$post_password) );
        
    $q = new WP_Query'p=$post_id' );
        if(
    $q->have_posts()){
            while(
    $q->have_posts()){
                
    $q->the_post();
                
    wp_redirect(get_permalink());
                die();
            }
        } else {
            
    // oh dear, there isnt a post with this 'password', put a redirect to a fallback here
            
    wp_redirect('http://www.google.com');
            die();
        }
        
    wp_reset_query();

    No matter what password I enter, the form just loads the latest post in the blog section of the site. I feel like there are some placeholders that I'm missing but don't know enough PHP to be able to figure anything out. Can any php-mags shed some light on this?

  2. #2
    Join Date
    Apr 2008
    Location
    Portland
    Posts
    246
    In your HTML, you probably left "action" blank on purpose, right?

    On the off chance........try putting the location of your "functions.php" file in there.

  3. #3
    Join Date
    Nov 2007
    Location
    MT
    Posts
    889
    Like I said, this is someone else's code and I'm trying to piece it together on my site.

    Tried putting the path of my functions.php in the "action" field in the HTML and I get this:

    Fatal error: Call to undefined function load_theme_textdomain() in /home/frigidli/public_html/wp-content/themes/modules/functions.php on line 9
    Last edited by OverTurn; 10-27-2011 at 09:55 PM.

  4. #4
    Join Date
    Apr 2008
    Location
    Portland
    Posts
    246
    I'd have to see the rest of the PHP in your functions.php file.....but right now you are missing a function called "load_theme_textdomain()".

    Honestly, I get the feeling I'm opening a huge can of worms here.

  5. #5
    Join Date
    Nov 2007
    Location
    MT
    Posts
    889
    Quote Originally Posted by 10% Groomed View Post
    I'd have to see the rest of the PHP in your functions.php file.....but right now you are missing a function called "load_theme_textdomain()".

    Honestly, I get the feeling I'm opening a huge can of worms here.
    Probably...I really have no idea what I'm doing with PHP and thought this would be more plug and play.

  6. #6
    Join Date
    Oct 2011
    Posts
    1
    In the WordPress deployments I've done the form action usually references PHP in the root of the wordpress directory (one of the wordpress core files or a file provided by a plugin). The functions.php file is generally for theme specific functions that get used often and is not used to handle a form. I would try putting the contents of the PHP snippet that you provided into a new file in the root of the wordpress directory (perhaps "login.php") and link to it in the form action (e.g. "action='login.php'"). Try adding "method='get'" to the form tag because the default is "get".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •