Frontend Form Field Ordering - Quick Fix [... NO FIX NEEDED]

7 years 3 months ago #18652 by Brat
In the form, the fields were ordering by field ID instead of the order I set in the administrator. A very quick fix is to do a customized sort on the $this->fields array to force it to order by ordering.

This was done in the actual form.php file.

First, add a function that actually sets up the sort to order by ordering:
function cmp( $a, $b )
{ 
  if(  $a->ordering ==  $b->ordering ){ return 0 ; } 
  return ($a->ordering < $b->ordering) ? -1 : 1;
} 

Now, usort (a built-in PHP function) your fields array. Make sure you call it of course before the fields render in the form:
usort($this->fields, "cmp");

The first parameter for usort is the name of the array. The second parameter is the sort criteria. Notice that the criteria name (in quotes) and the name of the function you defined must match.

So far, this is holding up and doesn't seem to cause any issues, but of course do test before using on your life site. 8-)

Please Log in or Create an account to join the conversation.

7 years 3 months ago #18656 by Rehne
Hi,

If I understand you correctly
you do not need this fix

look here
http://www.flexicontent.org/forum/index.php?f=26&t=2239&rb_v=viewtopic

Info for other users with same issue (field ordering in input form):
you can solve this by entering the Fields screen in the backend, filtering the fields by selecting the right type you want to set the ordering for (for example, the default content type), and THEN set the order by changing the arrows of providing index number and saving. The order will only apply to the content type you have filtered it on.


i think
certainly most FC users do not know that
therefore, it would be a good thing
to add a help text/note text (somehow)
in the fieldmanager

Regards

Please Log in or Create an account to join the conversation.

7 years 3 months ago #18671 by Brat
Thank you for pointing that out. However, I saw that post before, and truthfully just wanted to handle this really quickly because I have a lot to work on. The usort trick works easily. I will play with the other method when I have a moment, but right now I am doing battle with Flexiaccess. :lol:

Please Log in or Create an account to join the conversation.

7 years 3 months ago #18759 by Rehne

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.