• Resolved bbthoms

    (@bbthoms)


    Hi Tobias,

    Folgendes Szenario:

    Ich habe ein Seiten Template für eine Unterseite. Auf dieser Seite befindet sich ein Formular, welches direkt auch dort verarbeitet bzw. in Variablen via POST umgewandelt werden (klappt wunderbar). Möchte ich aber nun die Variablen in einer Tablepress Tabelle verwenden (ebenfalls auf der Seite eingebunden), sagt mir der Debugger immer die Variable sei nicht definiert.

    Ich habe es mit global probiert aber egal was ich mache es kommt nichts an.

    Hast du eine Idee woran es liegen könnte?

    Viele Grüße
    bbthoms

    https://ww.wp.xz.cn/plugins/tablepress/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    As these are the English-language forums, I’ll reply in English, so that more people can benefit from the discussion. I hope that’s ok.

    I assume that you are refering to the TablePress “PHP in tables” Extension here?
    Can you then maybe post some of your PHP code that you have in the table cells?

    Regards,
    Tobias

    Thread Starter bbthoms

    (@bbthoms)

    Hi Tobias,

    oh yes you’re right. Where I can edit my first post?

    Here is my code (simplified):

    <?php
    /*
    Template Name: Konf
    */
    ?>
    <?php
    $countobject1 = $_POST['object1'];
    if ($countobject1 == ''){
    	$countobject1 = '1';
    	}
    $countobject2 = $_POST['object2'];
    if ($countobject2 == ''){
    	$countobject2 = '1';
    	}
    $count_offn = $countobject1 + $countobject2;
    ?>
    .... etc. ...

    After that I get the page content (table via tablepress and the php extension). Within this table is written:

    <?php echo $count_offn; ?>

    In debug mode I get this error:

    Notice: Undefined variable: count_offn in /Applications/MAMP/htdocs/XXX/wp-content/plugins/tablepress-php-in-tables/tablepress-php-in-tables.php(26) : eval()'d code on line 1

    Cheers & Thx
    bbthoms

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    editing your first post is no longer possible, I think. Editing a published post in the forums is only allowed for up to an hour or so.

    Ok, so in the table, the PHP code is

    <?php echo $count_offn; ?>

    At that location, you will need to tell PHP to use the global variable, i.e.

    <?php echo $GLOBALS['count_offn']; ?>

    or (if you prefer that syntax)

    <?php global $count_offn; echo $count_offn; ?>

    Regards,
    Tobias

    Thread Starter bbthoms

    (@bbthoms)

    Hi Tobias,

    thank you for the fast reply. I tried the global but in the template file. Obviously it was the wrong place.

    Thank you very much!

    Cheers
    bb

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP Variable in Tablepress’ is closed to new replies.