I want to start by saying thank you to the SE community for helping out over the years.
I am trying to create a feature for our website that takes a customer zip code and updates the product inventory based on which of our partner distribution centers will fill the order. The form is simple, just a text box and a submit button. I have been working on it for a couple of weeks, but I can’t get the form to submit properly. I am using CF7 with Constant Contact plugin and Redirect for CF7 together as part of another feature, I am concerned that may be part of the problem.
Here is the form code:
<div id="zipsFormBox">
<form id="customerZip" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
<label for="customerZip">Zip Code</label>
<input type="text" name="customerZip" id="customerZip" placeholder="Enter Your Zip" required>
<input type="hidden" name="action" value="zipsForm">
<button type="submit">Submit</button>
</form>
</div>
The query var is there, but as you can see it is giving a 404.
It is supposed to run this (from functions.php):
add_action( 'admin_post_nopriv_zipsForm', 'process_form_data;');
add_action( 'admin_post_zipsForm', 'process_form_data');
…and process with:
function process_form_data() {
$customerZip = get_query_arg('customerZip');
if ( isset( $customerZip ) ) {
$submit_result = wp_unslash($customerZip);
echo("<br><p>" . "You Entered" . " " . $submit_result . " " . "as your zip code." . "</p>");
wp_die();
}
However, when I messed up and did this:
<div id="zipsFormBox">
<form
<label for="customerZip">Zip Code</label>
<input type="text" name="customerZip" id="customerZip" placeholder="Enter Your Zip" required>
<input type="hidden" name="action" value="zipsForm">
<button type="submit">Submit</button>
</form>
</div>
The form submits, query var goes to URL and the page reloads. Other than neither form running my PHP function, it does what I expect. I was hoping somebody could help me understand what is going on here. My thought is that the 404 may be coming from the action code in the form tag.
Any help is greatly appreciated!