0

i have php code it's for reading excel file (.xlsx) and i want to make plugin for Wordpress ( just a simple plugin ). tested on localhost Wordpress it's work perfectly, but when i uploaded to my site it's not work. when i click submit button just appear blank page.

<form method="post" action="">
Number : <input type="text" name"number" /> </br>
<input type"submit">
</form>




function find(){

    if (isset($_POST['number']) {
    $number = $_POST["number"];

    require_once ( plugin_dir_path(__FILE__). 'includes\classes\PHPExcel.php');
    $tmpfname = ( plugin_dir_path(__FILE__). 'number.xlsx');
    $excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
    $excelObj = $excelReader->load($tmpfname);
    $worksheet = $excelObj->getSheet(0);
    $lastRow = $worksheet->getHighestRow();
    $excel_arr = $worksheet->toArray(null,true,true,true);

        for ($row=1;$row <=$lastRow;$row++){

             if ($excel_arr[$row]["A"] == $number ) {
               echo $excel_arr[$row]["A"];
               break;
             }
        }
   }
}

add_shortcode('show_number', 'find');
7
  • The form needs to live inside the shortcode, otherwise there's no reason for the form to display. I'm curious how you got it to display in the first place - how are you accessing / including / referencing this code? Commented Aug 19, 2017 at 16:37
  • wordpress.stackexchange.com/questions/201650/… Commented Aug 19, 2017 at 16:38
  • already place The form to inside the shortcode but still doesn't work, please see my explanation, i have edited. I do not know, I just see on youtube. I do not really understand about php, I just learned: D Commented Aug 20, 2017 at 11:43
  • Hi Irfan - so, you are asking a new question, but within this old / existing question. If the original issue is resolved, then please upvote and / or accept an answer that helped you. Then, if you're now having problems with the Excel doc getting read / outputted, ask a new question about that. Commented Aug 20, 2017 at 13:04
  • 1
    No, it is not. The question is very different. It may be the same code for you, but the question is now different. We helped you fix the original problem, and now you've got a new problem with the same shortcode. Please ask a new question. Commented Aug 20, 2017 at 13:07

2 Answers 2

2

Insert HTML form code inside "find()" function. So form show with shortcode "show_number" and and get result.

Sign up to request clarification or add additional context in comments.

1 Comment

Already done but still load blank page, I think I'm wrong in writing function to read Excel file.
0
function find(){

    if (isset($_POST['number']) {
    $number = $_POST["number"];

    require_once ( plugin_dir_path(__FILE__). 'includes\classes\PHPExcel.php');
    $tmpfname = ( plugin_dir_path(__FILE__). 'number.xlsx');
    $excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
    $excelObj = $excelReader->load($tmpfname);
    $worksheet = $excelObj->getSheet(0);
    $lastRow = $worksheet->getHighestRow();
    $excel_arr = $worksheet->toArray(null,true,true,true);

        for ($row=1;$row <=$lastRow;$row++){

             if ($excel_arr[$row]["A"] == $number ) {
               echo $excel_arr[$row]["A"];
               break;
             }
        }
   }
   ?>
   <form method="post" action="">
    Number : <input type="text" name"number" /> </br>
    <input type"submit">
    </form>
   <?php
}

add_shortcode('show_number', 'find');
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.