Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-07-28 20:42:09

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Help to integrate complicated PHP contact form into the TXP

Hello,

I purchased a script that generates any contact form you can imagine, store the stuff in db and many other pleasant thing. To install it I have to –

1. Copy & Paste the following block of code at the very beginning of your .PHP file. (in my case txp page archive)

<txp:php>
            $get_form_info = 1;            
            $afp_form_id = 2;            
            include '[PATH_TO_AJAX_FORM_PRO]/ajax-form-app/common.php';            
</txp:php>

2. Copy & Paste the following block of code between the <head> and </head> tags of your page.

<txp:php>
 $afp->Init();
</txp:php>

3. Copy & Paste the following block of code where you want the form to show (between the <body> and </body> tags of your page)

<div style="width:<txp:php> $afp_area_width; </txp:php>;">
            	<div id="afp<txp:php> echo $afp_form_id; </txp:php>_wrap">            
            	<txp:php> if($afp_form_title) { </txp:php>
            		<h1><txp:php> echo $title; </txp:php></h1>
            	<txp:php> }            
            	/*
            	-----------------------
            	Include the AJAX Form
            	-----------------------
            	*/            
            	$afp->ShowForm($afp_form_id);
            	</txp:php>            
            	</div>
            </div>

And I get this –

Tag error:  <txp:php> ->  Notice: Undefined variable: afp while parsing form “None” on page “archive”
textpattern/publish/taghandlers.php:3836 eval()
textpattern/lib/txplib_publish.php:421 php()
textpattern/lib/txplib_publish.php:334 processTags()
textpattern/publish.php:544 parse()
index.php:83 textpattern()
Fatal error: Call to a member function Init() on a non-object in /home/user13274/domains/law.vpohod.info/public_html/textpattern/publish/taghandlers.php(3836) : eval()'d code on line 2

I wonder what am doing wrong? Thanx anybody who can help with that!

Last edited by admi (2013-07-29 18:42:52)

Offline

#2 2013-07-29 01:03:44

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Help to integrate complicated PHP contact form into the TXP

I could be wrong – but is it some to do with multiple blocks – from the How To page

*Escaping to XHTML*
While you can use multiple PHP blocks on a single page, each <txp:php>...</txp:php> block must be a valid block of code by itself. This means you can’t escape from PHP to HTML and back like you can with <?php ... ?>. This will not work:

Offline

#3 2013-07-29 07:18:58

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Help to integrate complicated PHP contact form into the TXP

Each of PHP block is executed in its own context, separate function scope. You will either have to put all that PHP code within a single block, or lift everything to a common namespace. This would of course require that the 3rd-party script doesn’t expect being run in global scope, which by looking at the code, might not be the case. So, you will have to format the code so that it can all be within single set of <txp:php> tags. Similarly to:

<txp:php>
    $foobar = true;
    include './foobar.php';

    $form = new Foo\Bar();
    $form->init();

    echo '<div style="width: '.$form_width.';" id="'.$form_id.'">';

    if ($title)
    {
        echo '<h1>'.$title.'</h1>';
    }

    $form->getFormContents();

    echo '</div>';

</txp:php>

You may also have to use global keyword to create or get variables in and from global namespace. E.g.

global $afp, $afp_form_id, $afp_form_area, $foobar;

By referencing all the global variables you need to retrieve and get from the external script at the beginning of your script.

Last edited by Gocom (2013-07-29 07:24:45)

Offline

#4 2013-07-29 09:52:21

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Help to integrate complicated PHP contact form into the TXP

On a side note, if it’s a purchased script you probably shouldn’t share it with others. Original author might get upset!

Offline

#5 2013-07-29 10:27:30

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Help to integrate complicated PHP contact form into the TXP

By referencing all the global variables you need to retrieve and get from the external script at the beginning of your script.

Thanks for the explaining the issue about the single block.

Last edited by admi (2013-07-29 10:28:15)

Offline

#6 2013-08-08 18:13:05

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Help to integrate complicated PHP contact form into the TXP

I wonder how to redo

$get_form_info = 1; $afp_form_id = 2;

Offline

Board footer

Powered by FluxBB