Hi all,

I have a website that uses Smarty templates and I want to create a new web page that includes a "contact us" form which utilizes a PHP form script that I bought. The script is actually a suite in that it generates the forms based on the fields you want in your form and it contains the script that processes submissions, send emails and inserts the data into a database.

Basically, I cant figure out how to convert the PHP, from the form, to Smarty. I've been searching this forum, the Smarty forum, Google and playing around with the page for days but I cant get it to work so I'm hoping someone on here can help me.

The Smarty templating system used on this website works by having a .php page and a .tpl page with the same name (e.g., testpage.php and testpage.tpl.). All of the PHP is supposed to go in the PHP page and the Smarty page is just supposed to be a template with variables and HTML.

Because this forum limits posts to 10,000 characters, I will attach the files instead of posting the code.

In the attached Zip archive, originalForm.php is the PHP form page that I generated using the form generator that I purchased. It is a whole page that can be uploaded to a website and be used as is but I need to split it's code into a seperate PHP and template file. If I upload and access this page from the Web, it works perfectly as is.

You will notice that originalForm.php is divided into three sections. It's set up this way to make it easy to integrate the form into any existing, standard Web page. Section 1 gets added to the very top of a given webpage, section 2 gets added to the head and section 3 gets added to the body of a page.

The other two files in the Zip archive are the PHP and template files I created but I get PHP errors. The header, part of the form, the PHP error and the footer are displayed when accessing ff.php from the Web. I took section 1 from originalForm.php and created the ff.php page. I then created the ff.tpl page by adding the section 2 and section 3 code from originalForm.php. In order for the section 2 code to be added to the head tag, I had to use the built-in Smarty {capture} function which works. I also had to change all of the PHP opening and closing tags to {php} and {/php}.

As I mentioned previously, when I access ff.php from the web, it partially loads and displays the following PHP error:

Fatal error: Call to a member function getTableTag() on a non-object in C:\www\mysite.com\include\smarty\templates_c\%%01^013^0133830D%%ff.tpl.php on line 61

The error is referring to echo $ffForm->getTableTag(); which is line 56 of ff.tpl.

That's were I'm stuck. According to Smarty guidelines, the template file (ff.tpl) is not supposed to contain any PHP. From what I gather, you are supposed to use only Smarty variables for what is in the PHP file.

I don't know how to remove all of the PHP from the template file, add it to the PHP file (ff.php) and create the Smarty variables that will be used in the template file.

Can someone lend me a hand, please 🙂

    I already did most of the work.

    I will pay someone $20 via PayPal if they can finish what I started.

      Write a Reply...