empty fields mean no show

Trying to get this to work for a little while now and getting frustrated. The end result is that if field 23 is filled, a dash will appear before it with spaces before and after the dash. If the filed is not filled, then the dash is not printed and the display is empty. Field 10 is the main portion of the address which is selected from a drop down box. So far I have:

[php]

<?php echo $title; ?>
<?php $arr = get_post_meta( get_the_ID(), '_wpbdp[fields][10]', true );

foreach ( $arr as $item) :
echo “$item”;
endforeach; ?> <?php $field = wpbdp_get_form_field( 23 );
if (isset($field)) { echo ’ - '; echo $field->html_value( $listing_id );}
if (empty($field)) { echo $field->html_value( $listing_id );} ?>

<?php $arr = get_post_meta( get_the_ID(), '_wpbdp[fields][22]', true );

foreach ( $arr as $item) :
echo “$item”;
endforeach; ?>

[/php]

Jason,

I’m a little confused basically you want to out put to look like

Assuming the $items are florida, nevada, and texas and 11111,22222,33333 for zips

[code]florida
nevada
texas

  • 23

11111
22222
33333

[/code]

Are you getting something different? Also you have an extra

, not sure why you have that there.

so the result, if there is no unit number should show as follows

address

If there is a unit number, it would show as

address - unit

I would like to do this without all the dashes being located in the database as “- unit #”. I understand this would probably be a conditional statement

Can you show me the result you’re getting now? The code that’s posted really doesn’t make sense to me from a logic standpoint.

Due to fussing customer, we had to put the dash in the database as part of the entry, so the dash is pulled with the information. However the issue still exists. Here is the php for our phone info. The result show be that if there is a phone number or email entered, then the label is created and the entry is provided. When no entry is there, no information is shown, not even the label.
Here’s the PHP:
[php]<?php $listing_id = get_the_ID(); ?>

<?php $field = wpbdp_get_form_field( 6 ); echo 'Tel: '; echo $field->html_value( $listing_id ); ?>
<?php $field = wpbdp_get_form_field( 24 ); echo 'Tel 2: '; echo $field->html_value( $listing_id ); ?>
<?php $field = wpbdp_get_form_field( 26 ); echo 'Fax: '; echo $field->html_value( $listing_id ); ?>
<?php $field = wpbdp_get_form_field( 8 ); echo 'Email: '; echo $field->html_value( $listing_id ); ?>

[/php]

Get the ID is a wordpress command to grab associations to the unique posting number for the item being called. “wpbdp_get_form_field (#)” is the setting required to grab the specified information that you need. Ne numbers co-inside with WordPress post ids to grab meta data on the post by the number… so “6” is “tel 1”, “24” is Tel 2, etc.

What is happening instead is that the fieild is blank, as expected, but the label is still showing up. As seen below:

[code]

Tel: 416.857.1654
Tel 2: 647.724.8825
Fax:
Email: [email protected]

[/code]

Try this… Test it out on just the fax field

Replace:

[php]echo 'Fax: '; echo $field->html_value( $listing_id ); ?>
[/php]

With:

[php]if (!empty($field->html_value( $listing_id ))) {
echo 'Fax: '; echo $field->html_value( $listing_id ); }?>
[/php]

Sorry. Getting total breakage with that. Nothing displayed at all, even removed what was previously there. Still got my headers and foorter

Turn on error reporting at the top of that page…

[php]<?php error_reporting(E_ALL); ?>[/php]

So we can see what the error messages are

hrrmm… no errors are output. I cleared the cashe just to make sure that wasn’t the issue.

so the code should look like this for fax, correct?

[php]<?php $field = wpbdp_get_form_field( 26 );
if (!empty($field->html_value( $listing_id ))) {
echo 'Fax: '; echo $field->html_value( $listing_id ); }?>[/php]

Yes,

Check your php.ini file and make sure it has this turned on…

display_errors = On

Thanks… . Never realized it was off.

Here is the readout, which is interesting:

[code]Warning: Missing argument 1 for WPBDP_FormField::html_value(), called in /chroot/home/thathost/thathost.co/html/dvbia2/wp-content/plugins/business-directory-plugin/templates/businessdirectory-listing.tpl.php on line 41 and defined in /chroot/home/thathost/thathost.co/html/dvbia2/wp-content/plugins/business-directory-plugin/api/form-fields.php on line 544

Notice: Undefined variable: post_id in /chroot/home/thathost/thathost.co/html/dvbia2/wp-content/plugins/business-directory-plugin/api/form-fields.php on line 545

Notice: Undefined variable: post_id in /chroot/home/thathost/thathost.co/html/dvbia2/wp-content/plugins/business-directory-plugin/api/form-fields.php on line 546

Warning: Invalid argument supplied for foreach() in /chroot/home/thathost/thathost.co/html/dvbia2/wp-content/plugins/business-directory-plugin/templates/businessdirectory-listing.tpl.php on line 43
Bio Wellness Holistic Centre
2428 Danforth Av
M4C 1K9[/code]

ok… I understand it… The following like is causing problems (from line 44):

[php]<?php $field = wpbdp_get_form_field( 29 );
echo $field->html_value(); ?>

<?php $arr = get_post_meta( get_the_ID(), '_wpbdp[fields][29]', true ); foreach ( $arr as $item) : echo "$item"; endforeach; ?>[/php]

Yeah, it’s much easier to debug when you have debugging turned on!

Glad I can help!

Thanks again. With that bug squashed, the code is working. Now I have to re-imliment it for each and then a few. This client is going to be the end of me. (Pixel Perfect as my college would call the customer)

uh oh… now it’s not working and there is no error output… php info says error reporting is on. Suddenly just not processing…

Sorry… it must have been me, the code is running again, but there is an oddity.

I used the same reference for my address line… Which was my first post on this issue. The code for the address is as follows:

[php]

<?php echo $title; ?>
<?php $arr = get_post_meta( get_the_ID(), '_wpbdp[fields][10]', true );

foreach ( $arr as $Address) :
echo “$Address”;
endforeach; ?> <?php if(!empty($Unit)) { echo '- '; echo $Unit->plain_value( $listing_id ); }?>

<?php $arr = get_post_meta( get_the_ID(), '_wpbdp[fields][22]', true );

foreach ( $arr as $Postal) :
echo “$Postal”;
endforeach; ?>

[/php] As you can see, the "- " is only suppose to show if $Unit has a value. I found a profile where the user did not have a unit number and the code is still outputting the "- ". [hr] Output: [code]

Tora Home Design
2686 Danforth Av -
M4C 1L7

[/code]

I noted I was missing the “->value( $listing_id )” and put it in, but this is what seems to be breaking me.

This seems to work though.

[php]<?php $def=$unit->html_value($listing_id);if(!empty($def)) { echo '- '; echo $unit->html_value( $listing_id ); }?>[/php]

Looks like I just needed to define another variable.

Thanks for the help again.

Awesome! Glad you figure it out.

I do the same thing 100% the time, as soon as I ask for help, I immediately solve it like 5 minutes later…

Sponsor our Newsletter | Privacy Policy | Terms of Service