Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

User Forms - Submissions Report Field Sorting


Go to End


6 Posts   2555 Views

Avatar
bmc38119

Community Member, 45 Posts

16 February 2010 at 7:58am

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
Avatar
Willr

Forum Moderator, 5523 Posts

16 February 2010 at 11:46am

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.

Avatar
bmc38119

Community Member, 45 Posts

16 February 2010 at 12:59pm

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).

Avatar
bmc38119

Community Member, 45 Posts

19 February 2010 at 9:50am

Edited: 19/02/2010 9:51am

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.

Avatar
bmc38119

Community Member, 45 Posts

19 February 2010 at 10:18am

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?

Avatar
bmc38119

Community Member, 45 Posts

20 February 2010 at 6:36pm

Edited: 20/02/2010 6:37pm

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.