Jump to content

Populating field values of cached forms with Markup Regions


Jonathan Lahijani
 Share

Recommended Posts

I wanted to share this tip which I'm going to implement on Transferware Collectors Club Database.

That site has a form which is a set of filters.  It takes many queries to build that form and all of its options and as a result, it takes over 5 seconds to load the page.  ProCache is out of the question because using a full page cache on a site like that doesn't make sense, but caching various areas with WireCache $cache does.

The form is developed in a way where it will automatically populate/select the various form fields based on what it reads from the URL.  So going to /?color=123 will automatically check the appropriate radio button for that color.  Therefore, when using $cache to cache the form (or parts of the form), we need to cache the form in a clean, unpopulated state.

The problem then becomes how do we use the cached form but also populate the fields accordingly based on the URL variables?  Markup regions can do this.

Assuming we had a set of radio options coming from our WireCache'd form like this:

...
<input type="radio" name="color" id="color-123" value="123"> Red
<input type="radio" name="color" id="color-124" value="124"> Blue
...

We could devise some code that also outputs this on our page:

<region pw-replace="color-123" checked></region>

Markup regions will then "check" that radio.

Perhaps this isn't mind blowing, but I've never thought of using Markup Regions in this way.

  • Like 7
Link to comment
Share on other sites

Cool tip, thanks!

6 hours ago, Jonathan Lahijani said:

It takes many queries to build that form and all of its options and as a result, it takes over 5 seconds to load the page.

As an aside, are you using findRaw() to get your data for the options? My experience lately is that when I make use of findRaw() I rarely need to cache this sort of thing because it's so much faster than loading whole Page objects.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...