1

I am really struggling on this one. This file works fine on my local dev site with no warnings. Putting it on a live site causes a fatal error, stopping the activation. I am finding it impossible to find the unexpected ending reason here. I have tried with two different live sites as well...

    <?php    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function the_note_form( $atts ){ 

    // prepare $home_page for defualt return to the homepage after note submit
    $home_page = get_home_url();
        //get current users id
        $users_id = get_current_user_id();
            // shortcode information
            $id_location_form = shortcode_atts( array( 'location' => '', 'title' =>'', 'redirect' => $home_page,  'category_custom' => '', 'create_logged_out' =>'', 'create_logged_in'=>'', 'create_by_user_id' =>'', 'show_setup' =>'', 'id_can_see' => '0' ), $atts );
                //get a time stamp for the note
                $entry_date = date('l jS \of F Y h:i:s A T'); //echo"$entry_date";
                    // get current users name
                    $user_info = wp_get_current_user(); $users_name = $user_info->display_name ;






if ($id_location_form['create_logged_in'] == 'yes' && is_user_logged_in() == "true") {include('form_build.php');}
        //logged out form
       if ($id_location_form['create_logged_out'] == 'yes' && is_user_logged_in() != "true") {include('form_build.php'); }

                //specify only a user id tha can access the form.
                if ($id_location_form['create_by_user_id'] == $users_id && $id_location_form['create_by_user_id'] != '') {include('form_build.php'); }



//if the show_setup = yes then show this var_dump of the setu array
if ($id_location_form['show_setup'] == "yes"){ ?> <pre> <?php print_r($id_location_form); ?> </pre>
<?
}

//close the function
}  

add_shortcode( 'the_note_input_form', 'the_note_form' );



  /****************************
form input to database
*******************************/



$security_input = 0;


if ( isset( $_POST["submit_form"] ) && $_POST["visitor_note"] != "" ) {


    $table = $wpdb->prefix."my_notes";
    $name = strip_tags($_POST["visitor_name"], "");
    $note = strip_tags($_POST["visitor_note"], "");
    $vis_id = strip_tags($_POST["visitor_id"], "");
    $input_location = strip_tags($_POST["input_location"], "");
    $date_stamp = strip_tags($_POST["utc_create"], "");
    $category_custom = strip_tags($_POST["category_custom"], "");
    $id_can_view = strip_tags($_POST["id_can_see"], "");
    $status = strip_tags($_POST["status"], "");

    $wpdb->insert( 
        $table, 
        array( 
            'name' => $name,
            'note' => $note,
            'user_id' => $vis_id,    
            'time_of_entry' => $date_stamp,
            'input_location' => $input_location,
            'category' => $category_custom,
            'id_can_view' => $id_can_view,
            'status' => $status,
            'security' => $security_input
        )
    );

}

This was marked as a duplicate by another user, yet, the issue was resolved around the difference between server setups, not strict syntax in itself as both were right, yet not obvious to the different setup. Not sure why the user marked this as a duplicate really...it also quizzed another user who missed the issue as well, so an interesting consideration to discuss as far as I can see.

1 Answers1

1

<? should be <?php ...

//if the show_setup = yes then show this var_dump of the setu array
if ($id_location_form['show_setup'] == "yes"){ ?> <pre> <?php                
print_r($id_location_form); ?> </pre>
<?php   // was <?
}

Note that on your local server, your PHP is probably configured to enable short open tags so <? is accepted as start of PHP code and so your code works locally. Your other server probably is doing the right thing by NOT enabling short open tags so <? is not recognized as the start of PHP code and so your code doesn't work there. Best to always use <?php as it always works.

BareNakedCoder
  • 3,257
  • 2
  • 13
  • 16
  • Oh wow, oh me oh my, thank you. Amazing how one setup will pickup these things and another wont. – digitalcreative.tech Dec 04 '16 at 19:23
  • Just updated my answer with reason why works 1 place but not other. Good idea to make sure using same config in both places (see php.ini). Very rare to see short open tags enabled in your local. I wonder if you have any other very old settings enabled that will bite you again. – BareNakedCoder Dec 04 '16 at 19:25
  • Yes, that makes complete sense. I knew that open tags are accepted, and I thought generally meant as a decoration to ensure other know it is php. Probably why I didn't consider it to be a possible reason. I have generally used them for good husbandry, but dropped this one and didn't consider it a possible cause for concern. Thanks again. I will always use them, so no matter where they may end up. It's a new setup, but it is a hard lesson learnt..I hope that I wont have such difficulties. – digitalcreative.tech Dec 04 '16 at 19:28