Submit a file from the frontend?
I am hoping someone can push me in the right direction here. I need to allow a user to upload a pdf file and have it attached to their page.
So I guess these are my questions:
Is there certain way to build the form?
Can an entry in a POD tie to a user login?
Or maybe there is an example somewhere?
Thanks! Shawn
7 Answers
It's pretty easy to do.
Install the package auto set current user. Create a new pod that has at least a file upload column for your PDF file and a Pick WP_Users field for the username. Assign the auto set current user helper as the input helper for the pick wp_users field. Then create a new pod page with code like this:
$pods = new Pod('my-pod');
$pods->publicForm();
That should get you going. The devil of course is in the details.
You'll still need to authenticate if the user is logged in before showing this form to just anyone. The public form function allows anyone to browse images on the server. You'll probably need to change that. And you'll also have to double check that both Wordpress and your PHP installation are configured to allow PDF uploads.
Excellent! Thanks. I will probably be back asking for some help slaying the devil...
Does anyone have any code example of this? I can get the generic public form to show. I am looking for ideas on how to authenticate a user and then send them to a form to upload a pdf or see a list of their files.
Thanks for any tips! Shawn
Wordpress takes care of the heavy lifting for you. As long as they are logged into your site, they are authenticated. Enclose your code in something like this:
if ( is_user_logged_in() ):
//Show template with form / files
else:
echo "<h2>Sorry</h2>\n<p>You don't have permission to use this resource. Please <a href='" . wp_login_url() . "' title='Login' >Login</a>\n";
endif;
Any tips on how to hide the Browse Server button. I have been searching, but no luck yet...
I now have a login page and can upload a pdf and link it to the user that is logged in. It goes to e People_file POD. I have my People POD with a PICK column that relates to People_file. I am struggling with getting that file to show up on my page. Do I need the PICK to bi-directional?
Here is the code I am trying to use. I pulled it from another post I found, but not sure if it is right. I can't seem to get the link to the file. Here is a link to the page, at the bottom on the right is a link that says "again again." http://cmfi.org/wherewework/missionary/npheald/
<?php
if (is_array($missionary_news)) {
echo '<ul>';
foreach ($missionary_news as $dl) {
echo '<li><a href="' . $dl['guid'] . '">' . $dl['name'] . '</a></li>';
}
echo '</ul>';
}
?>
edited Mar 1 at 9:15
Does anyone have any ideas about this? I am also trying to show only the last pdf of that user that was uploaded.
Thanks!


