form-action.php
-
Hi to all. Of course, I’m here because I’m facing issues with WordPress. ??
I’m struggling for quite some while now, to write from form to DB through custom made plugin. Here is my code.
<?php //Add Calendar to DB function acr_addRoom() { if ( isset($_POST["name"]) && isset($_POST["maxUnits"]) && isset($_POST["partlyBooked"]) > 0){ //get values from form $name = sanitize_text_field($_POST["name"]); $maxUnits = intval($_POST["maxUnits"]); $partlyBooked = intval($_POST['partlyBooked']); //inert into DB global $wpdb; $acr_rooms_table = $wpdb->prefix.'acr_rooms'; $wpdb->insert( $acr_rooms_table, array( 'name' => $name, 'maxUnits' => $maxUnits, 'partlyBooked' => $partlyBooked )); } } add_action( 'admin_post_acr_addRoom', 'acr_addRoom' ); ?> <div class="wrap"> <h1>Add Room Info</h1> <form method="post" action="admin-post.php"> <input type="hidden" name="action" value="acr_addRoom" /> <table class="form-table"> <tr> <td><label for="name">Name</label></td> <td align="left"><input name="name" placeholder="Room Type A" id="name" type="text" class="regular-text code" required /> </td> </tr> <tr> <td><label for="maxUnits">Number of rooms</label></td> <td align="left"><input placeholder="10" name="maxUnits" id="maxUnits" type="number" class="regular-text code" min="1" required /> </td> </tr> <tr> <td><label for="partlyBooked">Threshold for "partly booked"</label></td> <td align="left"><input placeholder="1" name="partlyBooked" id="partlyBooked" type="number" class="regular-text code" min="1" required /> </td> </tr> </table> <br /> <input class="button button-primary" type="submit" value="Add Room" /> </form> </div>
After I fill out the form I do not get insertion into database & page stops at admin-post.php. Does anybody know what do I do wrong?
Thanks.
BR.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘form-action.php’ is closed to new replies.