WordPress.org

Support

Support » Plugins and Hacks » Frontend Uploader » [Resolved] [Plugin: Frontend Uploader] Layout and collecting data

[Resolved] [Plugin: Frontend Uploader] Layout and collecting data

  • 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/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Rinat Khaziev

    @rinatkhaziev

    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.

    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

    Plugin Author Rinat Khaziev

    @rinatkhaziev

    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 ) );
        }
    }

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

    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.

    Plugin Author Rinat Khaziev

    @rinatkhaziev

    Hey saffyre9,

    I think you forgot to copy the last closing bracket.

    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 ) );
        }
    }
    ?>
    Plugin Author Rinat Khaziev

    @rinatkhaziev

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

    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' );
    Plugin Author Rinat Khaziev

    @rinatkhaziev

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

    Ok, thanks Rinat, I’ll keep looking!

    Dawn

    Plugin Author Rinat Khaziev

    @rinatkhaziev

    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 ) );
        }
    }

    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 ) );
        }
    }
    Plugin Author Rinat Khaziev

    @rinatkhaziev

    Thanks Josh!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] [Plugin: Frontend Uploader] Layout and collecting data’ is closed to new replies.
Skip to toolbar