Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How do I…?
  3. » Tag txp:php

#1 2014-11-07 19:13:51

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Tag txp:php

Textpattern a powerful CMS system with many tools.
My question is what can you build or how much can you write within textpattern using txp:php tag? Because I was trying to write a simple login page I was getting errors.

Thank you for your input.

Offline

#2 2014-11-07 19:20:56

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Tag txp:php

Hey code365 – what is the code you’re using and what errors are displayed?

Offline

#3 2014-11-07 19:43:28

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Re: Tag txp:php

Gawked thank you for your reply.

I deleted the code, decided to write raw php code outside Textpattern. I would like to try to keep as much txp:php code within TextPattern. But can you build a login screen…etc within Textpattern calling a data?

Thank you

Offline

#4 2014-11-07 19:45:46

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Tag txp:php

I can’t help you with the PHP code, I’m afraid – do you want to have users self-register and use your Textpattern site, or something else?

Offline

#5 2014-11-07 19:48:53

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Re: Tag txp:php

Yeah, that is the ideal for users self-register. Also I understand you can’t help with code part. But any input of what can txp:php allow you to do.

Last edited by code365 (2014-11-07 19:53:09)

Offline

#6 2014-11-07 19:52:20

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Tag txp:php

Take a look at mem_self_register – I haven’t used it, and I can’t say if it will work with the latest Textpattern, but it seems to do what you want.

Offline

#7 2014-11-07 21:36:03

code365
Member
From: California
Registered: 2009-08-16
Posts: 110
Website

Re: Tag txp:php

Thank you for your help but it do not work with the new TXP.

Last edited by code365 (2014-11-07 21:39:18)

Offline

#8 2014-11-07 22:23:08

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Tag txp:php

Here’s a short roundup on working with txp:php.

code365 wrote #285570:

[…] but it do not work with the new TXP.

Please read gaekwad’s post again :) Ah sorry, me too quicky ;)

Last edited by uli (2014-11-07 22:24:40)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#9 2014-11-08 09:57:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: Tag txp:php

The latest version of mem_self_register does work, though it can be fiddly to set up. There are alternatives such as cbe_frontauth and mck_login. Or if you want to roll your own you can combine plugins like rvm_privileged, or mem_form with mem_public_article or smd_query or etc_query.

Regarding what you can and can’t do in <txp:php>, pretty much anything you can do in PHP you can do in those blocks. Two caveats:

  • Anything you want to share across blocks or use from Textpattern (its globals for example) need to be imported/exported in your code’s scope using the global keyword.
  • Textpattern tags aren’t parsed. You need to use parse('<txp:some_tag attribute="value" ... />');
  • You can’t open conditionals in one block and complete them in another (like you can with raw <?php..?>). Each block has to be a complete, valid, self-contained lump of PHP.

Other than that, anything goes. So if you’re getting errors, throw some code here and we’ll see if we can get you on the right track.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2014-11-09 11:28:42

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Tag txp:php

Hi, i am writing here, instead of opening a new thread.
When I try to write the following code

<txp:php>
  include('csvtoservice.php');
  $content = csvtoservice('http://winterolympicsmedals.com/medals.csv');
  // if it could be loaded and parsed...
  if($content){
    // show the form
    echo '<h2>Filtri</h2>';
    if($content['form']){
      echo $content['form'];
    }
    // show the table
    if($content['table']){
      echo '<h2>Risultati</h2>';
      echo $content['table'];
    }
  }
</txp:php>

I get this error

Notice: Undefined offset: 8192 in /Applications/MAMP/htdocs/saba/textpattern/lib/txplib_misc.php on line 680
Tag error: <txp:php> ->  : Function split() is deprecated while parsing form None on page ricerca

csv to webservice is a PHP script to pull data from a CSV file on the web and turn it into a search and filter interface. Here is just a snippet of csvtoservice.php

<?php
function csvtoservice($url,$options){
  $csv = get($url);
  $lines = preg_split('/\r?\n/msi',$csv);
  $columns = split(',',
              strtoLower(
                preg_replace('/\s/','',$lines[0])
              )
            );
  $colstring = join(',',$columns);
.......

Can somebody help me to avoid above Tag error?

Thanks in advance

Offline

#11 2014-11-09 15:44:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: Tag txp:php

php split() is deprecated in php 5.3 upwards and txp is just notifying you of that. For simple splitting at a character/string, you can use explode in its place, for more complex splitting at a regular expression, use preg_split(). For example:

$columns = explode(',',
              strtoLower(
                preg_replace('/\s/','',$lines[0])
              )
            );

You may need to hunt down any other instances in your included script.


TXP Builders – finely-crafted code, design and txp

Offline

  1. Index
  2. » How do I…?
  3. » Tag txp:php

Board footer

Powered by FluxBB