I've been trying to get a basic plugin to work and I have followed what seems to be the flow to get the form to post to admin-post.php.
However, I only seem to get the white screen of death upon form submission.
This is my main plugin file
<?php
/**
* Plugin Name: Test form
*/
function wp_meetings_menu(){
add_menu_page('Meetings', 'Meetings', 'manage_options', 'wp_meetings', 'wp_meetings_form');
}
add_action('admin_menu', 'wp_meetings_menu');
function wp_meetings_form() {
?>
<div class="wrap">
<h2>Meetings</h2>
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>" enctype="multipart/form-data">
<label>Date and Time:</label>
<input type="datetime-local" name="datetime"><br><br>
<label>Drop Down 1:</label>
<select name="dropdown1">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select><br><br>
<label>Drop Down 2:</label>
<select name="dropdown2">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select><br><br>
<label>Drop Down 3:</label>
<select name="dropdown3">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select><br><br>
<label>PDF File:</label>
<input type="file" name="pdf_file"><br><br>
<input type="submit" name="submit" value="Submit">
<input type="hidden" name="action" value="wp_meetings_submit" />
</form>
</div>
<?php
}
?>
and this is the code in the functions.php file that is supposed to handle that submission to admin-post.php
// Handle form submission and database insertion
add_action( 'admin_post_wp_meetings_submit', 'wp_meetings_submit' );
add_action( 'admin_post_nopriv_wp_meetings_submit', 'wp_meetings_submit' );
function wp_meetings_submit(){
global $wpdb;
if(isset($_POST['submit'])){
$datetime = $_POST['datetime'];
$dropdown1 = $_POST['dropdown1'];
$dropdown2 = $_POST['dropdown2'];
$dropdown3 = $_POST['dropdown3'];
$pdf_file = $_FILES['pdf_file']['name'];
$upload_dir = wp_upload_dir();
$pdf_path = $upload_dir['path'] . '/' . $pdf_file;
move_uploaded_file($_FILES['pdf_file']['tmp_name'], $pdf_path);
$wpdb->insert(
'wp_meetings',
array(
'datetime' => $datetime,
'dropdown1' => $dropdown1,
'dropdown2' => $dropdown2,
'dropdown3' => $dropdown3,
'pdf_file' => $pdf_file
),
array(
'%s',
'%s',
'%s',
'%s',
'%s'
)
);
}
}
All I get when posting the form is a white screen of death with a blank die message error box.
I configured the WP_DEBUG to be true, but when recreating the error again, no debug log is generated.
I was wondering what is the correct and full way of accomplishing this?
WP_DEBUG
on its own won't create an error log?>
from the end of your plugins PHP file. You can also comment out parts of the code to determine which part is causing the problem. Additionally, how are you testing this? Nothing in your admin post handler redirects the user or displays any output, so of course the user is not redirected and sees nothing.admin-post.php
is also a very very old API, you can also let the page that serves the form also be the form handler