Display default value if field is left empty

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

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/

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

Hi Jason,

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

Regards,
Greg