Skip to content
Permalink
Browse files

Simple db insert from Submit button. Uses placeholder data.

  • Loading branch information...
MJGrant committed Jun 9, 2019
1 parent f05d341 commit b0d0f4ac5b5fcf7f48f4baec8fdb3778a0475c93
Showing with 52 additions and 37 deletions.
  1. +52 −37 amazin-product-box/amazin-product-box.php
@@ -8,6 +8,7 @@
* Author URI: http://majoh.dev
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
if ( is_admin() ){ // admin actions
add_action( 'admin_menu', 'amazin_plugin_menu' );
@@ -32,44 +33,46 @@ function amazin_render_form() {
<h2>Amazin' Product Box</h2>
<p>Create, edit, delete and manage your product boxes here.</p>
<div class="form-wrap">
<form action="<?php echo esc_url( post_new_product_box() ); ?>" method="post">

<!-- product box name -->
<div class="form-field">
<label for="product-box-name">Product Box name</label>
<input type="text" id="product-box-name" placeholder="Give this product box a useful name"/>
</div>

<!-- product name -->
<div class="form-field">
<label for="product-name">Product Name</label>
<input type="text" id="product-name" placeholder="Enter the product name here"/>
</div>

<!-- product tagline -->
<div class="form-field">
<label for="product-tagline">Product Tagline</label>
<input type="text" id="product-tagline" placeholder="Write a few words summarizing this product"/>
</div>

<!-- product description -->
<div class="form-field">
<label for="product-description">Product Description</label>
<input type="text" id="product-description" placeholder="Write about 100 characters explaining why this product is great."/>
</div>

<!-- product URL -->
<div class="form-field">
<label for="product-url">Affiliate link</label>
<input type="text" id="product-url" placeholder="http://amazon.com/affiliate-link-here"/>
</div>

<!-- Button text -->
<div class="form-field">
<label for="product-button-text">Button text</label>
<input type="text" id="product-button-text" placeholder="See XYZ product on Amazon.com"/>
</div>

<button>Add Product Box</button>
<!-- product box name -->
<div class="form-field">
<label for="product-box-name">Product Box name</label>
<input type="text" id="product-box-name" placeholder="Give this product box a useful name"/>
</div>

<!-- product name -->
<div class="form-field">
<label for="product-name">Product Name</label>
<input type="text" id="product-name" placeholder="Enter the product name here"/>
</div>

<!-- product tagline -->
<div class="form-field">
<label for="product-tagline">Product Tagline</label>
<input type="text" id="product-tagline" placeholder="Write a few words summarizing this product"/>
</div>

<!-- product description -->
<div class="form-field">
<label for="product-description">Product Description</label>
<input type="text" id="product-description" placeholder="Write about 100 characters explaining why this product is great."/>
</div>

<!-- product URL -->
<div class="form-field">
<label for="product-url">Affiliate link</label>
<input type="text" id="product-url" placeholder="http://amazon.com/affiliate-link-here"/>
</div>

<!-- Button text -->
<div class="form-field">
<label for="product-button-text">Button text</label>
<input type="text" id="product-button-text" placeholder="See XYZ product on Amazon.com"/>
</div>

<input type="submit"/>
</form>

</div>
<?php
@@ -103,4 +106,16 @@ function amazin_render_table() {
return;
}
function post_new_product_box() {
$my_post = array(
'post_title' => 'Test product box',
'post_content' => 'Test description',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database.
wp_insert_post( $my_post );
}
?>

0 comments on commit b0d0f4a

Please sign in to comment.
You can’t perform that action at this time.