Search

I just noticed the attachment field for posting on the forum with the Add more + link. Simply smart! Is it possible for the symphony team to share how this was done and how we can duplicate it? I can see this being a great extension for the back and front end.

Cheers!

You find this jQuery code in attachments.js:

jQuery(document).ready(function() {
    $ = jQuery;

    var added = 0;
    var removed = 0;
    $("#add-attachment").live('click', function(e){
        e.preventDefault();
        added++;
        $(this).before("<input id='form-attachment-" + added + "' type='file' name='attachments[" + added + "]'/>");
    });

    $("#files-attached .remove").live('click', function(e){
        var fileid = $(this).siblings("a.download").attr("id");
        e.preventDefault();
        removed++;

        $(this).parent().addClass("removed");
        $(this).text("Restore").attr("class", "restore");

        $("#files-attached").after("<input type='hidden' id='removed-" + fileid + "' name='attachments[remove][" + removed + "]' value='" + fileid + "' />");
    });

    $("#files-attached .restore").live('click', function(e){
        var fileid = $(this).siblings("a.download").attr("id");
        e.preventDefault();

        $(this).parent().removeClass();
        $(this).text("Remove").attr("class", "remove");

        $("#removed-" + fileid).remove();
    });

});

I think he was talking about how it works with Symphony. Usually you can only attach a single file per upload field in an entry. This forum allows you to duplicate an upload field.

Is this done by an extension or is there a section link happening there?

Thanks Michael! Now, how hard would it be to add this to the backend? ;)

@MrBlank: So I am not the right guy to answer this. The HTML output makes me think that it is “custom coded”, but I am not really sure. Maybe the team can tell.

@carlos:

Now, how hard would it be to add this to the backend? ;)

There are some threads discussing UI solutions to easily handle section links. I guess this is what you are missing in the backend. Unfortunately, the team has not revealed any future plans at the moment, and the only extension bringing s.th. like this to the backend (the Sub Section Field) has been deprecated. So I am afraid we have to wait.

That’s what I was thinking originally. I didn’t realize you could duplicate an upload field, always thought it was limited to one entry.

always thought it was limited to one entry

Yes, see my post above – you will have to use section link functionality (or “custom code”).

Again, thanks Michael. Hopefully the team will chime in with their magic.

Is this done by an extension or is there a section link happening there?

A section link. A section “Attachments” has two fields: File (File Upload) and Parent (Select Box Link, linked to the forum Comments section).

If you create an event and select “Allow Multiple” you can then submit multiple files (entries) into your Attachments field in one form submit. If you set the “fields[parent]” of each to be the ID of the Comment, they will attach to the right parent. The JavaScript on the frontend is used to duplicate a row containing the form elements, incrementing the “index” used in the HTML input name attributes.

Then create a Data Source from the Attachments section filtering the “Parent” Select Box Link field by the comment ID you’re viewing. That way you can re-build the list of currently-attached files.

This is definitely do-able with native functionality. It’s actually a good exercise because it uses some powerful concepts:

  • multiple sections
  • section links (using Select Box Link)
  • parent/child relationships
  • events
  • submitting multiple entries using one event
  • filtering Data Sources

An idea for a tutorial!

Getting this into the backend is another case entirely. The Sub-Section is deprecated. There is hope that the idea of native sub-sections will one day be a reality.

But why Sub-Section extension is deprecated? (I’m completely lost)

Nick’s solution is not how we do it, however it is the way to do it using just native fields and such. The only problem with the approach is saving attachments against a yet to be saved entry, as there is no ID to populate the parent field with.

The way we did it was using an Attachments section, like Nick pointed out, but instead of the allow multiple functionality and a separate event, we use an extension that makes available a new Event filter called “Save Attachments”. It subscribes to the post saving delegate of the Event code and monitors POST data, looking for $_POST['attachments'][]. If it finds any, it uses the ID created by the event, which is passed to the delegate, and saves that value as the parent field.

It’s a fairly simple approach. The only caveat is that if an attachment fails to upload, it wont stop any entry from getting saved (comment or discussion etc) as the delegate it uses appears after the saving process. One solution to this is to use the pre saving delegate to first check the attachment data, and throw errors if there are any problems.

If anyone is interested, I can post the extension.

But why Sub-Section extension is deprecated? (I’m completely lost)

There has been a discussion about this.

Note that we have scoped out and are experimenting with the concept of making the event system in Symphony accommodate for a “chaining” effect. This enables saving of an entry and have the result sent to another event to use. Thereby allowing linking of sections in a single process.

Allen, would this be a backend (admin) feature?

This’ll be a new feature for the events editor. The concept will be similar to DS Output Param, but for events. We’re also looking at exposing the parameter pool to the events.

A totally contrived example would be setting $current-date to the date field through the event editor.

A more practical example would be to set the $event-blog-save to the System ID field.

Note that this is just a concept that we’re toying around with and I’m hoping that it’ll get more refined as we go further.

Allen, would this be a backend (admin) feature?

Frontend.

Frontend

Hmmm. Backend workflow: unsolved. :-(

@Alistair I’d definately like to see the extension. I guess it’s better to have one end then none at all… Boy, that line can be taken in many ways ;)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details