The image you posted isn't the homepage like I was talking about. I wanted a way for the user, from the homepage, to quickly create an alert for a city/state without having to drill down.
I managed to figure it out myself.
In main.php I placed this
<h3><strong><?php _e('Location', 'bender'); ?></strong></h3>
<div class="row one_input">
<?php ItemForm::region_select(osc_get_regions(osc_user_country()), osc_user()); ?>
<select id="sCity" name="sCity">
<option value="">Any City</option>
</select><br /><br /><h3><strong><?php _e("Email Address", 'bender') ; ?></strong></h3><br />
<input type="text" name="email" class="form-control" id="email"><br /><br />
<input type="hidden" id="sRegion" width="10" name="sRegion" value="" />
<div class="form-group">
<button class="btn btn-success" id="save">Subscribe for location alerts</button><br /><br />
</div>
</div>
<Script>
$('#regionId').change(function updateCityList() {
var actualRegionId = $(this).val();
if ( Math.floor(actualRegionId) == actualRegionId && $.isNumeric(actualRegionId)) {
/*Get cities per region*/
$.ajax({
url: "<?php echo osc_base_url(true); ?>?page=ajax&action=cities",
data: { regionId: actualRegionId },
success: function( cities, err){
var $el = $("#sCity"),
citiesOptions = {};
$('#sCity option:gt(0)').remove();
$el.val("");
$el.prev("span").text("Any City");
$.each(cities, function(key, value) {
$el.append($("<option></option>")
.attr("value", value.s_name).text(value.s_name));
});
$("#sRegion").attr("value", $("#regionId option[value='"+actualRegionId+"']").text());
},
dataType: "json"
});
}
});
$(document).on("click", "#save", function () {
//get value of message
var state = $("#sRegion").val();
var city = $("#sCity").val();
var email = $("#email").val();
//check if value is not empty
if(state == '' || city == '') {
$("#error_message").html("Please enter information");
return false;
} else {
$("#error_message").html("");
}
//Ajax call to send data to the insert.php
$.ajax({
type: "POST",
url: "ajaxinsert.php",
data:{state:state, email:email, city:city},
cache: false,
success: function (data) {
//Insert data before the message wrap div
$(data).insertBefore(".state-wrap:first");
//Clear the textarea message
$("#email").val("Subscription Added");
}
});
});
</script>
I created a file called "ajaxinsert.php" and inside is this code:
<?php
require_once 'ajaxconfig.php';
if (isset($_POST['email'])) {
$state = $_POST['state'];
$city = $_POST['city'];
$email = $_POST['email'];
mysqli_query($conn, "INSERT INTO oc_t_alerts (s_email, fk_i_user_id, s_search, s_secret, b_active, e_type, dt_date) VALUES ('".$email."', '0', '{\\\"price_min\\\":0,\\\"price_max\\\":0,\\\"aCategories\\\":[],\\\"city_areas\\\":[],\\\"cities\\\":[\\\"oc_t_item_location.s_city LIKE \'".$city."\' \\\"],\\\"regions\\\":[\\\"oc_t_item_location.s_region LIKE \'".$state."\' \\\"],\\\"countries\\\":[],\\\"withPattern\\\":false,\\\"sPattern\\\":null,\\\"tables\\\":[],\\\"tables_join\\\":[],\\\"no_catched_tables\\\":[],\\\"no_catched_conditions\\\":[\\\"1 = 1\\\"],\\\"user_ids\\\":null,\\\"order_column\\\":\\\"dt_pub_date\\\",\\\"order_direction\\\":\\\"desc\\\",\\\"limit_init\\\":0,\\\"results_per_page\\\":50}', 'yQXlLoai', '1', 'DAILY', '2019-06-27 09:10:17')");
echo '<div class="message-wrap">Subscription added</div>';
} else {
echo "Message is empty";
}
?>
ajaxconfig.php just has my DB credentials in it.
Works fine, and alerts function as desired.