Advertisement:

Author Topic: [Solved] Any way to have a drop down for email alerts?  (Read 116 times)

disbeliever

  • Newbie
  • *
  • Posts: 2
[Solved] Any way to have a drop down for email alerts?
« on: June 24, 2019, 06:42:14 pm »
Hello,

Has anyone figured out how to add an email alert to the Bender homepage, that would give you a drop down of cities and a text box to put email address in to submit for email alerts to that city?

I see the alert-form.php that is called into the category page, but if there anyway to add in a variable for what I am looking to do at the top level?
« Last Edit: July 02, 2019, 07:23:47 pm by disbeliever »

BritWeb

  • Hero Member
  • *****
  • Posts: 770
  • If it ain't broke, don't fix it.
Re: Any way to have a drop down for email alerts?
« Reply #1 on: June 28, 2019, 03:17:44 am »
Hello,

Has anyone figured out how to add an email alert to the Bender homepage, that would give you a drop down of cities and a text box to put email address in to submit for email alerts to that city?

I see the alert-form.php that is called into the category page, but if there anyway to add in a variable for what I am looking to do at the top level?

if a user chooses a city and presses the apply button, the listings for that search (city) will be displayed and the user could save that search. See the pic attached.

Regards

disbeliever

  • Newbie
  • *
  • Posts: 2
Re: Any way to have a drop down for email alerts?
« Reply #2 on: July 02, 2019, 07:21:54 pm »
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

Code: [Select]
   <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:

Code: [Select]
<?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.