Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Display default value if field is left empty

 

 


gversion
User

Nov 26, 2011, 2:25 PM

Post #1 of 6 (1295 views)
Shortcut
Display default value if field is left empty Can't Post

Hello,

I have a WYSIWYG field for users to describe their listing, however it is not a required field and very often it is left blank.

Is there a way I can display a default value on the front-end website if the user does not type anything?

For example, if the the user doesn't type in a description then I can display at the front-end:

"For further details about this product please contact the advertiser...".

Thank you,
Greg


zip222
User

Nov 26, 2011, 6:41 PM

Post #2 of 6 (1287 views)
Shortcut
Re: [gversion] Display default value if field is left empty [In reply to] Can't Post

Are you looking to do this on a listing page, or a detail page?

here is the basic php you will need...

<?php
if(!$field_name) {
echo "<p>Enter default stuff here... </p>";
}
else echo $field_name;
?>

$field_name will need to be updated based on your cms setup. and it will be a little different if it's a listing page versus a detail page.


gversion
User

Nov 27, 2011, 4:47 AM

Post #3 of 6 (1264 views)
Shortcut
Re: [zip222] Display default value if field is left empty [In reply to] Can't Post

Hi,

Thanks for the reply. I'd like to do this on a detail page.

How does the code change?

Thanks again,
Greg


gversion
User

Nov 27, 2011, 5:31 AM

Post #4 of 6 (1260 views)
Shortcut
Re: [gversion] Display default value if field is left empty [In reply to] Can't Post

Hi,

Do you know why this code isn't working?


Code
if(!$listingsRecord['list_price']) {  
echo "<p>No price specified</p>"; 

else
echo "<? php $listingsRecord['currency']?> <? php $listingsRecord['list_price'] ?>";
?>

Thank for you help!

Greg


Jason
Staff / Moderator


Nov 27, 2011, 11:08 AM

Post #5 of 6 (1245 views)
Shortcut
Re: [gversion] Display default value if field is left empty [In reply to] Can't Post

Hi Greg,

You're not going to need the <?php tags inside your string, since you're already in a PHP block,

try this:


Code
<?php 
if(!$listingsRecord['list_price']) {
echo "<p>No price specified</p>";
}
else {
echo $listingsRecord['currency'].$listingsRecord['list_price'];
}
?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/ 


gversion
User

Nov 28, 2011, 3:51 AM

Post #6 of 6 (1210 views)
Shortcut
Re: [Jason] Display default value if field is left empty [In reply to] Can't Post

Hi Jason,

Thanks for the help. It was the concatenation symbol I needed to know about!

Regards,
Greg