WordPress.org

Ready to get started?Download WordPress

Forums

Frontend Uploader
[resolved] Layout and collecting data (15 posts)

  1. aly22
    Member
    Posted 1 year ago #

    This plugin works for upload, but two issues:

    1. The layout is strange -- all in a paragraph. I would like line breaks between fields so it looks like this:

    Upload your Image: browse and select photo
    Description: optional image description
    Your name: enter name
    Your email: enter email
    Submit button

    Instead it looks like this: Description ----- Photo ---- Caption---Email ---Name Submit

    Note: the ---- dashes are input fields.

    I tried using
    between shortcode, but no luck.

    Here's the code inserted in my post:

    [fu-upload-form class="your-class" title="Upload your media"]
    [textarea name="caption" class="textarea" id="ug_caption" description="Description (optional)"]
    [input type="file" name="photo" id="ug_photo" class="required" description="Your Photo"]
    [input type="text" name="email" id="ug_email" class="required" description="Your email"]
    [input type="text" name="name" id="ug_name" class="required" description="Your name"]
    [input type="submit" class="btn" value="Submit"] [/fu-upload-form]

    2. Although I am requesting email, description and other info, I do not see that information anywhere when I check the image in admin. What am I missing?

    http://wordpress.org/extend/plugins/frontend-uploader/

  2. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Hey,

    Regarding the first issue, plugin comes with no CSS at all, so you have the freedom to style it as you want. I might include some basic styles in the future release. Thanks for bringing that up.

    Regarding the second one, it requires additional setup involving configuration filter. Place something like that in your functions.php.

    <?php
    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    
    function my_fu_after_upload( $attachment_ids ) {
        // do something with freshly uploaded files
        // This happens on POST request, so $_POST will also be available for you
        foreach( $attachment_ids as $att_id ) {
        	// Format the title
        	$author = 'By ' . $_POST['name'];
        	$author .= ' ' . $_POST['email'];
        	// Sanitize input from user
        	$author .= sanitize_text_field( $author );
        	wp_update_post( array( 'ID' => $att_id, 'post_title' => $author ) );
        }
    }

    Let me know if that makes any sence.

  3. digidale
    Member
    Posted 1 year ago #

    Hi Rinat,

    I've been trying something similar here, and the $_POST variables get returned as "Array". For instance, I tried the snip you pasted above, and the title of the uploaded file was set to "By Array Array". Do you know why this would be?

    Plugin is working great otherwise.

    Thanks

  4. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry digidale,

    I didn't test the code, here's the proper version, that one should work.

    <?php
    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    
    function my_fu_after_upload( $attachment_ids ) {
        // do something with freshly uploaded files
        // This happens on POST request, so $_POST will also be available for you
        foreach( $attachment_ids as $att_id ) {
    		// Format the title
        	$author = 'By ' . $_POST['name'][0];
        	$author .= ' ' . $_POST['email'][0];
        	// Sanitize input from user
        	$author = sanitize_text_field( $author );
        	wp_update_post( array( 'ID' => $att_id, 'post_title' => $author ) );
        }
    }
  5. digidale
    Member
    Posted 1 year ago #

    thanks Rinat, got it now! Great plugin - 5 stars for you my friend.

  6. saffyre9
    Member
    Posted 1 year ago #

    Hi Rinat,

    I'm trying to copy the same form and I've added the action to my function file, but I'm getting the following error:

    Parse error: syntax error, unexpected $end in /home/saffyre9/public_html/jenandjp_ca/wp-content/themes/Feather/functions.php on line 323

    I'm not really familiar enough with PHP to understand where the issue is.

  7. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Hey saffyre9,

    I think you forgot to copy the last closing bracket.

  8. saffyre9
    Member
    Posted 1 year ago #

    Hi Rinat,

    I've got the closing ?> bracket, and don't see a missing } bracket.

    This is eactly what I've got:

    <?php
    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    
    function my_fu_after_upload( $attachment_ids ) {
        // do something with freshly uploaded files
        // This happens on POST request, so $_POST will also be available for you
        foreach( $attachment_ids as $att_id ) {
    		// Format the title
        	$author = 'By ' . $_POST['name'][0];
        	$author .= ' ' . $_POST['email'][0];
        	// Sanitize input from user
        	$author = sanitize_text_field( $author );
        	wp_update_post( array( 'ID' => $att_id, 'post_title' => $author ) );
        }
    }
    ?>
  9. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Hey saffyre9,
    Can you post here what's on line 323 and before it?

  10. saffyre9
    Member
    Posted 1 year ago #

    323 is the opening of <?php for this action. 322 is the closing ?> of the previous action.

    ?>
     <?php
    add_action( 'fu_after_upload', 'my_fu_after_upload' );
  11. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Hmm that means that the problem is before 322 line, still, it's gotta be missing bracket.

  12. saffyre9
    Member
    Posted 1 year ago #

    Ok, thanks Rinat, I'll keep looking!

    Dawn

  13. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    I just updated the plugin and fixed underlying bug, so the new snippet will look like:

    <?php
    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    
    function my_fu_after_upload( $attachment_ids ) {
        // do something with freshly uploaded files
        // This happens on POST request, so $_POST will also be available for you
        foreach( $attachment_ids as $att_id ) {
    		// Format the title
        	$author = 'By ' . $_POST['name'];
        	$author .= ' ' . $_POST['email'];
        	// Sanitize input from user
        	$author = sanitize_text_field( $author );
        	wp_update_post( array( 'ID' => $att_id, 'post_title' => $author ) );
        }
    }
  14. JoshKay
    Member
    Posted 1 year ago #

    Hey, I know this is old, but if you want to use $_POST to update the description of the updated file, you can use the following code. $_POST['name'] corresponds to name="name" in the shortcode form, and 'post_content' is the description field ('post_excerpt' is the caption field). Hope that helps somebody!

    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    
    function my_fu_after_upload( $attachment_ids ) {
        // do something with freshly uploaded files
        // This happens on POST request, so $_POST will also be available for you
        foreach( $attachment_ids as $att_id ) {
    		// Format the title
        	$author = $_POST['name'];
        	$author .= ' ' . $_POST['email'];
    		// Change the description
    		$description = 'Upload by ' . $_POST['name'];
    		$description .= ', ' . $_POST['email'];
    		$description .= ' ' . $_POST['post_title'];
        	// Sanitize input from user
        	$author = sanitize_text_field( $author );
        	wp_update_post( array( 'ID' => $att_id, 'post_title' => $author, 'post_content' => $description ) );
        }
    }
  15. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks Josh!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.