Jump to content

Access to HTML (apparently) generated in PHP


sproutee

Recommended Posts

Dear all,

 

I am in the process of creating an HTML5 template for use with my WHMCS installation. This includes a total rehaul of forms as they are laid out and styled in the default theme. This is where I've hit a snag.

 

It does not appear to be possible to manipulate the HTML that is used with Custom Client Fields in forms. The custom fields are inserted into the TPL as

 

{$customfield.input} {$customfield.required}

 

There is no HTML+Smarty in the TPL and no access to the PHP, so it is not possible to update the inline styles injected into the input or dynamically fill in the

for

attribute of a dynamically generated

label

element.

 

So, how can I proceed with my template building when not all of the HTML is available in the TPL (or JS) files, but, seemingly, also generated at the server side?

 

For reference I am working with v4.5.2. Have all such cases been resolved in version 5?

 

Any help is gratefully received.

Link to comment
Share on other sites

wrap them in a div and modify them with jQuery.

 

<div id="customfields">
{$customfield.input} {$customfield.required}
</div>

{literal}
<script>
$(document).ready(function() {
 var i=0;
 $('#customfields').find(':input').each(function() {
   // Do something with $(this)
   var type = $(this).attr('type');
   $(this).attr('id', 'customfield_'+i;
   if (type == 'text') {
     $(this).addClass('myCustomClass');
   }
   $(this).parent().append('<label for="customfield_'+i+'">My Label</label>');
   i++;
 });
});
</script>
{/literal}

 

This is obviously completely untested and probably wont even work, but will give you an idea on how to tackle the issue.

Link to comment
Share on other sites

Hi Frank,

 

Good call. I am familiar with manipulating the view with jQuery and in the absence of a fully MVC framework it looks as if this is the sort of methodology I'll need to adopt for the increasing number of server-side injected styles/HTML I'm coming across. It works, but is a lot of extra coding that *shouldn't* be necessary - ah well.

 

Thanks a lot for taking the time to write some sample code, very kind of you.

 

Best wishes,

Meg

Link to comment
Share on other sites

Indeed, and to be fair the vast majority of the HTML is in the templates, but for a paid for product I would 100% full separation of tiers and failing that the choice to fiddle with the PHP/server side logic.

 

Thanks again for taking the time to give a detailed reply. Very helpful to know that I didn't miss something and that a frontend work around is the means to the end.

Link to comment
Share on other sites

  • 4 weeks later...

Hi, have just finished my implementation of a work around and here's what I came up with. Help yourselves if it's useful to you.

 

For the label and layout I updated the relevant TPL files as follows:

 

<label for="customfield{$customfield.id}">{$customfield.name}</label>
{$customfield.input}
<p class="custom_desc">{$customfield.description}</p> 

 

In this way a label with the correct for attribute is generated and the description text positioned and styled as desired.

 

To deal with the inline style injected into the width of the input box I created a custom-field.js file with the following:

 

jQuery(document).ready(function(data) {
  jQuery("*[id^='customfield']").each(function () {
       jQuery(this).width(250);
   }); 
});

 

Using jQuery's attribute starts with selector, it is possible to go through all the custom input elements and update their width to my spec. I import this file where appropriate.

 

Hope this helps until such a work around is not longer required.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated