-1

i want to export two different type of xlsx file based on radio button .

    $sel = $_POST['sel'];
       echo $sel;

    if(isset($_POST['search'])){

        if($sel == 'board')
        {
         header('Location: export_data1.php? 
       num='.$_POST['staff']);  
       die(); 
        }
       else
       {

         header('Location: export_data2.php? 
          num='.$_POST['desg']);
         die(); 

        }
       }

how to call another php file based on my radio button.Is there any other alternate way to call php file with passing arguments?

antony
  • 3
  • 6

1 Answers1

0

Your page of form where you will create form

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>"method="post">
    <!-- radio button -->
    <input type="radio" name="sel" value="board">
    <input type="radio" name="sel" value="your_other_value">
    <!-- radio button -->
   <!-- Drop Down -->
    <input type="option" name="boardlist" value="board">
    <input type="option" name="desgwise" value="Designation">
    <!-- radio button -->

    <input type="hidden" name="staff">
    <input type="hidden" name="desg">
    <input type="submit" name="search">
</form>
</body>
</html> 

This is your export_data1.php file

<?php
if(isset($_POST['search'])){
    if($sel == 'board'){
        header('Location: export_data.php?num='.$_POST['boardlist'];
    } else {
        header('Location: export_data1.php?num='.$_POST['desgwise'];
    }
}
?>

export_data & export_data1 have different format for export xlsx file

F5 Buddy
  • 474
  • 4
  • 4
  • Is this Jeopardy? What's different with this approach here? What's `$sel`? – Progrock Nov 20 '18 at 08:04
  • I assume the difference here is that instead of having two separate export scripts, you are merging them into one script. I think I prefer the separation of responsibility, unless the code is practically identical. Differentiated URLs could also be a good thing. – Progrock Nov 20 '18 at 08:17
  • i separate into two files. action="export_data1.php?desg=" is it correct method to passing parameters – antony Nov 20 '18 at 08:58