简体   繁体   中英

PHP code showing in browser

I have some PHP code in my .php file which is showing as it is in the browser. As in, I want the code to execute on form submit, but its showing as plain text in the browser.

<?php
 if(isset($_POST['ss-submit']))//submit button name
  {

 //Describing the Leads object and printing the array
 $describe = $connection->describeSObjects(array('Lead'));
 print_r($describe);
 ?>

Below it is an HTML form which displays correctly.

now this .php file is included in a .tpl file.

You can keep your both files different. In case of smarty the php file is executed first process data and then with the help of assign function you can assign your output from php to the tpl file.

Try as much as you can process data at the php page only

<?php
 if(isset($_POST['ss-submit']))//submit button name
  {
  //Describing the Leads object and printing the array
  $describe = $connection->describeSObjects(array('Lead'));
  $smarty->assign('lead_array',$describe);
 ?>
  1. Replace $smarty with your smarty object

  2. Replace lead_array with a name with which you want to access array in .tpl file

now on the .tpl page you can simply write

{$lead_array|print_r}

make sure your form on the .tpl page post on the same php file

it will print your array

This is a sure solution try it once and you will get desired output.

in a .htaccess file

AddType application/x-httpd-php .php .html .tpl

beware this parses all tpl files as if they were php. A templating engine may be better

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM