Results 1 to 6 of 6
Thread: PHP Help #2
-
10-27-2011, 07:35 PM #1
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>
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();
}
-
10-27-2011, 09:07 PM #2
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.
-
10-27-2011, 09:31 PM #3
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 9Last edited by OverTurn; 10-27-2011 at 09:55 PM.
-
10-27-2011, 09:55 PM #4
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.
-
10-27-2011, 09:56 PM #5
-
10-27-2011, 10:18 PM #6Minion
- 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".
Bookmarks