Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit3ffe6583e345496a03fb4785d1469772c8e3081d (patch)
Author
 pgmatev <petargabriel.matev@gmail.com>
2020-07-15 14:03:38 +0300
Committer
 pgmatev <petargabriel.matev@gmail.com>
2020-07-15 14:03:38 +0300
Files3bac78e096e258304b30a51fee7f1c759e7c82c0
tues-interns-2020-feature/publish-offers.tar
tues-interns-2020-feature/publish-offers.tar.gz
tues-interns-2020-feature/publish-offers.zip
Parentd631407b79d7507f6c9829268b7ecf24ccb3fc21 (diff)
issues with post from custom template feature/publish-offers
2 files changed, 51 insertions, 10 deletions
-rwxr-xr-xwp-content/plugins/dx-vehicles/vehicles-class.php40
-rw-r--r--wp-content/themes/carmag/templates/publish-offers.php21
diff --git a/wp-content/plugins/dx-vehicles/vehicles-class.php b/wp-content/plugins/dx-vehicles/vehicles-class.php
index 3a0b127..7f6b100 100755
--- a/wp-content/plugins/dx-vehicles/vehicles-class.php
+++ b/wp-content/plugins/dx-vehicles/vehicles-class.php
@@ -4,6 +4,8 @@ class Vehicles {
add_action( 'init', array( $this, 'cpt_create' ) );
add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) );
add_action( 'save_post', array( $this, 'vehicle_info_save_meta' ), 1, 2 );
+ add_action( 'admin_post_process_offer', array( $this, 'process_offer_data' ));
+
}
public function labels() {
@@ -121,4 +123,42 @@ class Vehicles {
}
}
}
+
+ function process_offer_data () {
+ $post_data = array(
+ 'vehicle-year' => $_POST['vehicle-year'],
+ 'vehicle-millage' => $_POST['vehicle-millage'],
+ 'vehicle-horsepower' => $_POST['vehicle-horsepower'],
+ // 'vehicle-range' => sanitize_text_field( isset( $_POST['vehicle-range'] ) ? $_POST['vehicle-range'] : null ),
+ 'vehicle-price' => $_POST['vehicle-price'],
+ 'vehicle-images' => $_FILES['vehicle-images'],
+ );
+
+ // Cycle through the $events_meta array.
+ // Note, in this example we just have one item, but this is helpful if you have multiple.
+ foreach ( $events_meta as $key => $value ) {
+ if ( $value == null ) {
+ continue;
+ }
+
+ switch ( $key ) {
+ case 'vehicle-year':
+ if( strcmp( "1769", $value ) > 0 || strcmp( "2020", $value ) < 0 ) wp_die( 'Invalid year' );
+ break;
+ case 'vehicle-millage':
+ if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid millage.' );
+ break;
+ case 'vehicle-horsepower':
+ if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid horsepower.' );
+ break;
+ case 'vehicle-range':
+ if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid range.' );
+ break;
+ case 'vehicle-price':
+ if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid price.' );
+ break;
+ }
+ $post_id = wp_insert_post( $post_data );
+ }
+ }
}
diff --git a/wp-content/themes/carmag/templates/publish-offers.php b/wp-content/themes/carmag/templates/publish-offers.php
index 81e5f02..4caf0d1 100644
--- a/wp-content/themes/carmag/templates/publish-offers.php
+++ b/wp-content/themes/carmag/templates/publish-offers.php
@@ -12,7 +12,8 @@
get_header(); ?>
<div class="section-fullwidth inverted">
- <form method="POST" action="">
+ <form method="POST" action="<?php echo admin_url( 'admin-post.php' ) ?>">
+ <input type="hidden" name="action" value="process_offer">
<h1>Publish offer</h1>
<div class="offer-info">
<h2>What is your vehicle type ?</h2>
@@ -22,7 +23,7 @@ get_header(); ?>
<span id="motorcycle" class="type"><i class="fas fa-motorcycle"></i></span>
<span id="tractor" class="type"><i class="fas fa-tractor"></i></span>
<span id="bus" class="type"><i class="fas fa-bus"></i></span>
- <input type="hidden" name="category" id="category" value="car">
+ <input type="hidden" name="vehicle-category" id="category" value="car">
</div>
<div class="specifications">
<h2>Specifications about your vehicle</h2>
@@ -31,11 +32,11 @@ get_header(); ?>
<option selected="" value="">Brand</option>
</select>
- <select class="models" id="models" name="model">
+ <select class="models" id="models" name="vehicle-model">
<option selected="" value="">Model</option>
</select>
- <select class="fuelType" name="fuel">
+ <select class="fuelType" name="vehicle-fuel">
<option selected="" value="">Fuel type</option>
<option value="Gasoline">Gasoline</option>
<option value="Diesel">Diesel</option>
@@ -43,25 +44,25 @@ get_header(); ?>
<option value="Hybrid">Hybrid</option>
</select>
- <select class="condition" name="condition">
+ <select class="condition" name="vehicle-condition">
<option selected="" value="">Condition</option>
<option value="Factory new">Factory new</option>
<option value="Used">Used</option>
<option value="For parts">For parts</option>
</select>
- <select class="gearbox" name="gearbox">
+ <select class="gearbox" name="vehicle-gearbox">
<option selected="" value="">Gearbox</option>
<option value="Manual">Manual</option>
<option value="Automatic">Automatic</option>
<option value="Semi-automatic">Semi-automatic</option>
</select>
- <input type="text" class="input" id="year" name="year" placeholder="Year">
+ <input type="text" class="input" id="year" name="vehicle-year" placeholder="Year">
- <input type="text" class="input" id="horsepower" name="horsepower" placeholder="Horsepower">
+ <input type="text" class="input" id="horsepower" name="vehicle-horsepower" placeholder="Horsepower">
- <select class="types" name="type">
+ <select class="types" name="vehicle-type">
<option value="">All categories</option>
<option value="Hatchback">Hatchback</option>
<option value="Coupe">Coupe</option>
@@ -110,7 +111,7 @@ get_header(); ?>
<div class="description">
<h2>Add a short description about your offer</h2>
- <input type="text" class="input desc" id="description" name="description">
+ <input type="text" class="input desc" id="description" name="vehicle-description">
</div>
<button type="submit" class="publishOfferButton button secondary" form="publishOffer" value="publishOffer" >Publish offer</button>