Jump to:

10844 Posts in 2515 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » User Forms - Submissions Report Field Sorting

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1570 Views
  • bmc38119
    Avatar
    Community Member
    45 Posts

    User Forms - Submissions Report Field Sorting Link to this post

    Willr - first off, thank you for the awesome user forms module.

    i have one question regarding how the SubmittedFormField data is being reported on the Submissions tab. If you see on the attached screenshot, the submitted data fields appear in different order each time the form is submitted. i made no changes to the form configuration while inserting these 3 sample submissions back-to-back. as you can see, the earliest sorted the submitted fields according to the order of the fields in the form (which is the way i want it), but the more recent ones are sorted differently.

    I looked at the template that is being rendered for this report in the cms and it appears to be pulling in FieldValues. Is there a way to alter the way the fields are being sorted to make sure the Fields are being presented in the proper order. It's not a big deal when there are 4 fields, but I will be adding more and it will start to be pretty messy.

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: User Forms - Submissions Report Field Sorting Link to this post

    Glad you like the module! I haven't thought about the issues with ordering before so you bring up a good point.

    The order that they're written into the database should be the order of the fields in the CMS. So if you reorganize the ordering in the cms then the future submissions will follow the new order in the cms (but the old ones will still be in the same order) as you're noticed, I think the only way to get round that would be to store a sort value in the SubmittedFormField.

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: User Forms - Submissions Report Field Sorting Link to this post

    Not sure if this is a good fix b/c does require manual alteration of the database table, but it seems to work.

    i noticed phpMyAdmin that some of the "newer" records were being written at the "top" of the table despite having a higher ID value than the existing records (the lowest ID value was 116 and there were records with higher ID value at the "top" of the table).

    I went into Operations tab on the SubmittedFormField table and changed "Alter table order by" to ID ascending. All fields now reflect the order in which they are entered on the contact Form (I also changed the field sort order on the contact form several times, resubmitted and it worked every time).

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: User Forms - Submissions Report Field Sorting Link to this post

    Nevermind, this solution did not last. apparently changing the table sort order in mysql is only for that time you have done it. i went back and checked today and it is not sorting them correctly after submitting some samples today.

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: User Forms - Submissions Report Field Sorting Link to this post

    Willr, i think the way to get around this would be just get FieldValues to be sorted by ID ascending. The records are being written to the database and assigned a correct incremental ID in the order they appear on the form, but they are actually being placed into the database table in different "order" (in other words, possibly filling the "spot" of previously deleted rows - thus appearing higher in the table). See attached screenshots.

    userforms-screenshot1.png = reflects records inserted into database table immediately after submitting form (notice how the ID value is not in any order)
    userforms-screenshot-sortID.png = reflects records after i manually sort the table by ID (which shows the records are actually being assigned the correct incremental ID that reflects the order they are presented in the form)

    Is there a way to hook into FieldValues and get it to sort by ID ascending. Maybe i need to write a custom function to pull this data?

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: User Forms - Submissions Report Field Sorting Link to this post

    I have got this working now with the following code. I could not figure out how to properly extend the SubmittedForm class and get this method to work, so i just went ahead and hacked the module code (i know, not supposed to do this).

    i am not sure if you are interested in adding this to the official module code, but this is how i solved it (and I am sure others are bound to come across this issue).

    Since the only thing that needed to happen was to sort the FieldValues by ID ascending, I added the following function to SubmittedForm.php:

       function SortedFieldValues() {
          $mySet = $this->FieldValues();
          $mySet->sort('ID');
          return $mySet;
       }

    I then replaced the FieldValues Control block on SubmittedFormReportField.ss with:

    <% control SortedFieldValues %>
       <tr>
          <td class="field">$Title</td>
          <td class="value">$Value</td>
       </tr>
    <% end_control %>   

    All the fields are sorted in the correct order in the report now.

    1570 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.