Display default value if field is left empty

6 posts by 3 authors in: Forums > CMS Builder
Last Post: November 28, 2011   (RSS)

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

Re: [gversion] Display default value if field is left empty

By zip222 - November 26, 2011

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.

Re: [zip222] Display default value if field is left empty

Hi,

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

How does the code change?

Thanks again,
Greg

Re: [gversion] Display default value if field is left empty

Hi,

Do you know why this code isn't working?

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

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

Thank for you help!

Greg

Re: [gversion] Display default value if field is left empty

By Jason - November 27, 2011

Hi Greg,

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

try this:

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


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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