Php Function In A Tpl

Hello guys

i was wondering if there was a way to put a php funtion in a tpl file to retrieve data from the database and cross check it with data entered in a textbox in the tpl before an order is submitted.

Is this possible? Can you add php to the tpl? if so, how can i add the code into a validate button?

Thanks guys

Hello guys

i was wondering if there was a way to put a php funtion in a tpl file to retrieve data from the database and cross check it with data entered in a textbox in the tpl before an order is submitted.

Is this possible? Can you add php to the tpl? if so, how can i add the code into a validate button?

Thanks guys

It is not a good practice to mix different types of code. The template files are responsible for the look and feel of the store and should not have anything to do with the actual functionality for which PHP code is responsible. Now we do our best not only to improve CS-Cart functionality but also to preserve the consistent code and keep the good coding style.

Cs-cart uses variable modifiers throughout their code base which is simply “calling a php function from within a template”. Google “smarty variable modifiers” for details.


In practice it is best to pass data as variables, but it is not always reasonable to do so.


In the situation you describe, JS and an Ajax call is probably more appropriate for form element validation.

Is it possible to add a button in the tpl to validate the data entered in a separate php file might be a pop up window then return the results and display them in the tpl file. I have a table in the database with codes which need to be entered by the user before an order is submitted.

Cs-cart uses variable modifiers throughout their code base which is simply "calling a php function from within a template". Google "smarty variable modifiers" for details.

In practice it is best to pass data as variables, but it is not always reasonable to do so.

In the situation you describe, JS and an Ajax call is probably more appropriate for form element validation.

I have a php file to check for the code do you have an example of how to create a button to pass the code from a textbox in the tpl to the php file and the response back to the tpl? Any example?

// Simple syncronisation example
$pesa = new PLUSPEOPLE\PesaPi\PesaPi();

if(isset($_POST[“receipt”]))
{
$transactions=$pesa->locateByReceipt($_POST[“receipt”]);
if(count($transactions)>0)
{
?>

Pesapi Payment received - congratulations Pesapi

Pesapi

	
	
	
	

Pesapi

You are ready to pay - the price is 50KES Send the money via Mpesa to: 022222222

	
	
	

	

Thanks guys

Use php functions in the following way

{$all_items = $arg1|fn_get_custom_items:$arg2:$arg3:$arg4:$arg5}