html form POST_ not populating DB/ email

I have read quite a few advice on the subject in the forum but none of the methods worked for me.
I have included an HTML form into a page template.

        <script type="text/javascript" src=""></script>
        <script type="text/javascript">
          const url = "";
          $.getJSON(url, function(data){
            $('#selector').append('<option selected="true" disabled>Choose a beach</option>')
            $('#selector').prop('selectedIndex', 0);
            $.each(data, function(key,entry){
              $('#selector').append($('<option>').text(entry.Beach).attr('value', entry.Id))});
        <script type="text/javascript">
        function validateForm(){
          /* Validating name field */
          var x=document.forms["myForm"]["name"].value;
          if (x==null || x=="") {
            alert("Name must be filled out");
            return false;
          /* Validating email field */
          var x=document.forms["myForm"]["email"].value;
          var atpos=x.indexOf("@");
          var dotpos=x.lastIndexOf(".");
          if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){
            alert("Not a valid e-mail address");
            return false;
          var x=document.forms["myForm"]["date"].value;
          if (x==null || x=="") {
            alert("The date must be filled out");
            return false;
          var x=document.forms["myForm"]["selector"].value;
          if (x==null || x=="") {
            alert("The beach must be selected");
            return false;
          var x=document.forms["myForm"]["weight"].value;
          if (x==null || x=="") {
            alert("The weight must be provided");
            return false;
      <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post" name="myForm">
      <input type="hidden" name="action" value="pollution_data">
      Name:<br> <input id="name" type="text" name="name" /><p>
      Enter your email:<br> <input type = "email" id="email" name="email" /><p>
      Date of collection: <input type="date" id="date" name="date" class="datepicker" /><p>
      Choose a beach: <select id= "selector" name="Choose_beach"></select><br>
      If the beach is not listed please use the contact form<p>
      Weight collected in kg: <input id="weight" type="number" name="weight" /><p>
      Feedback: <br><textarea name="feedback" rows="10" cols="50" ></textarea><p>
      <input type="submit" value="Submit" /></form>

I have modified the function.php to export my POST data via admin_post but nothing seems to work. Here an exert of the function.

 * Manage form
add_action( 'admin_post_nopriv_pollution_data', 'add_pollution_data' );
add_action( 'admin_post_pollution_data','add_pollution_data');
function add_pollution_data(){	
//get the form elements and store them in a variable
	if (! is_page("contribute-to-marine-pollution-data-collection")||! isset( $_POST['name'] )) {
	function test_input($data) {
	  $data = trim($data);
 	 $data = stripslashes($data);
 	 $data = htmlspecialchars($data);
	  return $data;
	define('DB_HOST', 'host');
	define('DB_USERNAME', 'user');
	define('DB_PASSWORD', 'pwd');
	define('DB_NAME', 'DB');
//get connection
	$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
 	 die("Connection failed: " . $mysqli->error);
//insert data
	$query1 ="INSERT INTO <code>TAB1</code> (a,b,c,d) VALUES ($beach, $date,$weight,$email)";
	$result1 = $mysqli->query($query1);
//free memory associated with result
//close connection
// Sanitize E-mail Address
	$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
	$email= filter_var($email, FILTER_VALIDATE_EMAIL);
	if (!$email){
 	 echo "Invalid Sender's Email";
	$subject ="Data Submission";
	$headers ='From:';
	$message = wordwrap("name:t$namenemail:t$emailndate:t$datenbeach:t$beachnWeigth:t$weight $unitnmsg:n",70);
	echo "Thanks for the submission!";
	//Redirects to the success page

I don’t think the function is read and I don’t really find a way of debugging this. Any help is welcome.

The page I need help with: [log in to see the link]

Source link