Exporting a form to a CSV file does not work in WordPress but it does in PHP

I have a form with some fields that I need to implement in a WordPress template. If I do it in vanilla PHP it works but when I put it in a WordPress template it doesn't work, can it be a problem with $_POST?

?php
/**
 * Template Name: Telesales
 */
?

?php if(isset($_POST['submit'])){

    
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $DOFMonth = $_POST['DOFMonth'];
    $DOFDay = $_POST['DOFDay'];
    $DOFYear = $_POST['DOFYear'];

    
   

        $Content = Name,LastName,Birthday\n;
        $Content .= $firstName,$lastName,$DOFMonth-$DOFDay-$DOFYear\n;

        $FileName = $firstName.-.date(d-m-y-h:i:s)..csv;
        header('Content-Type: application/csv'); 
        header('Content-Disposition: attachment; filename=' . $FileName . ''); 
        echo $Content;
        exit();
    
} ?

form action= method=post

  labelFirst name/label
  input type=text name=firstName placeholder=Rose required= value=
  br

  labelLast name/label
  input type=text name=lastName placeholder=McDonnell required= value=
  br

  labelDate of Birth/label
  select name=DOFMonth required=
    option value=nullMonth/option
    option value=JanuaryJanuary/option
    option value=FebruaryFebruary/option
  /select

  select name=DOFDay required=
    option value=nullDay/option
    option value=11/option
    option value=22/option
    option value=33/option
    option value=44/option
    option value=55/option
  /select
  select name=DOFYear required=
    option value=nullYear/option
    option value=19201920/option

  /select


  input type=submit name=submit value=Submit

/form

Topic csv forms export Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.