Click here to Skip to main content
14,134,253 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I write a php code that read text file and it is working fine with no problem , have a look at this code.
<?php
function Read($filepath)
{
$myfile = fopen($filepath,"r") or die("Unable to open file!");
$label=fread($myfile,filesize($filepath));
fclose($myfile);
echo $label;
}
?>

now if i try to use Read function inside below input it works fine

<input type="text" id="txtname" name="txtname" placeholder="<?php Read("resources/name_ar.txt");?>" />


I need to do the same thing using a wordpress plugin but i can't . have another look on below code
<?php
/*
Plugin Name: my plugin
Description: my plugin
Version: 4.0
Author: me
License: GPL
*/
?>
<?php
//PHP Function to read resources files.
function Read($filepath)
{
$myfile = fopen($filepath,"r") or die("Unable to open file!");
$label=fread($myfile,filesize($filepath));
fclose($myfile);
echo $label;
}
?>

<?php
function  form_creation()
{
    global $wpdb;
    ob_start();
?>
<form action="<?php get_permalink();?>" method="post" id="myform">
<table>
<tr>
<td>
    <h2>Asking Support</h2>
</td>
</tr>
<tr>
<td> <input type="text" id="txtname" name="txtname" placeholder="<?php Read("resources/name_ar.txt");?>" /> </td>
</tr>

</table>
</form>
<?php return ob_get_clean(); } ?>
<?php add_shortcode('myshortcode',form_creation); ?>


now when i use myshortcode nothing displayed and i think that because read function didn't be accessed , so how can Read function be accessed by form creation function

keep in mind , if form_creation() has no nested function , it will work and form displayed .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 29 Dec 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100