1

We are trying to break up a form into several pages using jQuery steps. The error points to the form that we're trying to create. Call to the form initially looks like this:

$enable_paid_submission = houzez_option('enable_paid_submission');
$user_pack_id       = get_the_author_meta( 'package_id' , $userID );
$remaining_listings     = 0;

if( is_page_template( 'submit_property_test.php' ) ) {

    if( $enable_paid_submission == 'membership' && $remaining_listings != -1 && $remaining_listings < 1 ) {
        print '<div class="user_package_status"><h4>'.esc_html__('HTMLhere.','houzez' ).'</h4></div>';

<?php
            $layout = houzez_option('property_form_sections');
            $layout = $layout['enabled'];

            if ($layout): foreach ($layout as $key=>$value) {
                switch($key) {
                    case 'features':
                        get_template_part( 'features' );
                        break;
                    case 'location':
                        get_template_part( 'location' );
                        break;
                    case 'multi-units':
                        get_template_part('multi-units');
                        break;
                }
            }
            endif;
            ?>

We would like to break the three sections of the form (features, location and multi-units) into three different pages. We added jQuery steps and it now looks like the following:

    <script>
        $(function ()
        {
            $("#wizard").steps({
                headerTag: "h2",
                bodyTag: "section",
                transitionEffect: "fade"
            });
        });
    </script>

    <div id="wizard">
        <h2>Features</h2>
        <section>
            <?php
            $layout = houzez_option('property_form_sections');
            $layout = $layout['enabled'];

            if ($layout): foreach ($layout as $key=>$value) {
                switch($key) {
                    case 'description-price':
                        get_template_part('features');
                        break;
                    }
            }
            endif;
            ?>
        <h2>Location</h2>
        <section>
            <?php
            $layout = houzez_option('property_form_sections');
            $layout = $layout['enabled'];
            if ($layout): foreach ($layout as $key=>$value) {
                switch($key) {
                    case 'description-price':
                        get_template_part('location');
                        break;
                    }
            }
            endif;
            ?>
        </section>
        <h2>Multi-units</h2>
        <section>
            <?php
            $layout = houzez_option('property_form_sections');
            $layout = $layout['enabled'];
            if ($layout): foreach ($layout as $key=>$value) {
                switch($key) {
                    case 'description-price':
                        get_template_part('multi-units');
                        break;
                    }
            }
            endif;
            ?>
        </section>

It was running okay in the first few hours. Now it is returning the error.

cErApHiM
  • 15
  • 6
  • Is that a JavaScript error or a PHP error? If a PHP error (which I would expect, due to the placement of the string `'enabled'`), please update your tags accordingly. – Heretic Monkey Sep 14 '16 at 18:23
  • It's actually a PHP error in a Wordpress site. Added PHP as one of the tags. Thanks for the catch. – cErApHiM Sep 14 '16 at 18:37

1 Answers1

0

It looks like you are expecting the the function call to houzez_option() to return an array. It would seem from the error that you are getting that it is not. Without seeing what the houzez_option() code looks like it is impossible to tell you why it is not.

You could still improve your code some by having it check specifically for what you expect to be returned from your function.

        $layout = isset( $layout['enabled'] ) ? $layout['enabled'] : '';
        if ( is_array( $layout ) ): foreach ($layout as $key=>$value) {
            switch($key) {
                case 'description-price':
                    get_template_part('features');
                    break;
                }
        }
        else:
            echo 'Unable to retrieve options';
        endif;

This will prevent the error and alert you that it isn't working on the frontend. You could also make the message clearer for the enduser. I was just providing a generic example.

BA_Webimax
  • 2,714
  • 1
  • 13
  • 15
  • It does make the error go away, however, the form elements do not appear there anymore as well. It now consists of a blank form. I have edited my initial inquiry to include houzez_option(). – cErApHiM Sep 15 '16 at 06:44
  • @cErApHiM I'm not seeing the function definition. You should also verify what is being returned by `$layout = houzez_option('property_form_sections');` by following that with a `var_dump( $layout );` – BA_Webimax Sep 15 '16 at 13:38