Jump to content

custom field input placeholder value


wulfric

Recommended Posts

how do i add the description into the placeholder input field?

 

so for example, this code:

{$customfield.input}

 

turns into this html:

<input type="text" name="customfield[4]" id="customfield4" value="" size="30" class="form-control">

 

and I wish to add a placeholder attribute using the smarty snippet. the above html would like:

 

<input type="text" name="customfield[4]" id="customfield4" value="" size="30" class="form-control" placeholder="{$customfield.description}">

 

--

 

latest WHMCS using stock six theme and standard_cart order form

 

file

\templates\orderforms\standard_cart\configureproduct.tpl

 

line 241 - 261

{if $customfields}

   <div class="sub-heading">
       <span>{$LANG.orderadditionalrequiredinfo}</span>
   </div>

   <div class="field-container">
       {foreach $customfields as $customfield}
           <div class="form-group">
               <label for="customfield{$customfield.id}">{$customfield.name}</label>
               {$customfield.input}
               {if $customfield.description}
                   <span class="field-help-text">
                       {$customfield.description}
                   </span>
               {/if}
           </div>
       {/foreach}
   </div>

{/if}

Link to comment
Share on other sites

I would think it would be a spin-off from my post in the thread below...

 

https://forum.whmcs.com/showthread.php?117998-Change-additional-domainfield-to-placeholder&p=476354#post476354

 

... that thread was about additional domain fields, but they're just custom domain fields by another name. :)

 

at a guess, and I haven't tested this, but I assume it would be something along the lines of replacing {$customfield.input} with...

 

{if $customfield.input|strpos:'<input type="text"'===0}{$customfield.input|replace:"/>":" placeholder="`$customfield.description`"/>"}{else}{$customfield.input}{/if}

Link to comment
Share on other sites

What does the '===0 mean? is there a way to close that properly so sublime doesn't report it as fizzy-wuzzy? I noticed in sublime text editor, it detects bad code and changes all the text thereafter.. like normally everything is pretty color coded and when something is broke, it'll highlight **** as gold / yellow.

 

When I cross-checked with the link you posted, you forgot two back slashes. I added them and this is the code that works perfect.

 

{if $customfield.input|strpos:'<input type="text"'===0}{$customfield.input|replace:"/>":" placeholder=\"`$customfield.description`\"/>"}
{else}
{$customfield.input}
{/if}

 

i also took it a step further, and chose to hide the description field below for a specific product id, and this was what i used to do that (just in case anyone else wants to do this):

 

{if $customfield.description}
   <span class="field-help-text">
   {if $productinfo.pid eq "123"}
   {else}
   {$customfield.description}
   {/if}
   </span>
{/if}

Link to comment
Share on other sites

What does the '===0 mean?

http://us3.php.net/manual/en/language.operators.comparison.php

 

$a === $b will be TRUE if $a is equal to $b, and they are of the same type.

and for strpos, where we're checking if a substring starts a string, the documentation specifically states...

 

Use the === operator for testing the return value of this function.

I suppose technically we don't need to check if it starts with the substring, but only if it exists somewhere in the string... I was probably just being painstakingly accurate. :idea:

 

is there a way to close that properly so sublime doesn't report it as fizzy-wuzzy? I noticed in sublime text editor, it detects bad code and changes all the text thereafter.. like normally everything is pretty color coded and when something is broke, it'll highlight **** as gold / yellow.

I can't really help you with Sublime as i've never used it, I tend to code in Notepad++ - and sometimes that will not colour the code correctly... especially when your mixing Smarty and PHP functions - it's just one of those things... i've learnt to trust my coding and it's results. :)

 

I also took it a step further, and chose to hide the description field below for a specific product id, and this was what i used to do that (just in case anyone else wants to do this):

which you could trim down slightly...

 

{if $customfield.description}
   <span class="field-help-text">
   {if $productinfo.pid neq "123"}{$customfield.description}{/if}
   </span>
{/if}

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