*

Web

  • ****
  • 183 posts
Ad Post
« on: November 23, 2020, 07:44:48 PM »
Posting Ads without select city

How to prevent?

*

MB Themes

Re: Ad Post
« Reply #1 on: November 23, 2020, 10:38:51 PM »
Location required plugin, theme settings, ...
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #2 on: November 24, 2020, 04:31:36 AM »
theme settings location enabled

Only some users

How to add server  side validation?

*

MB Themes

Re: Ad Post
« Reply #3 on: November 24, 2020, 02:45:14 PM »
@Web
I am not sure if any of solution has also server side validation, probably easiest way is to create function that is executed after publishing and will check if location was entered or no.

Code: [Select]
function check_location_not_empty() {
  $messages = array();
  $country_required = true;
  $region_required = true;
  $city_required = true;

  if($country_required && Params::getParam('countryId') == '' && Params::getParam('country') == '') {
    $messages[] = __('Country is required!', 'theme');
  }

  if($region_required && Params::getParam('regionId') == '' && Params::getParam('region') == '') {
    $messages[] = __('Region is required!', 'theme');
  }

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_post_url());
    exit;
  }
}

osc_add_hook('pre_item_post', 'check_location_not_empty', 1);

You may also check Backoffice manager plugin.
https://osclasspoint.com/osclass-plugins/backoffice/backoffice-manager-plugin_i49
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #4 on: November 25, 2020, 08:02:57 PM »
@Web
I am not sure if any of solution has also server side validation, probably easiest way is to create function that is executed after publishing and will check if location was entered or no.

Code: [Select]
function check_location_not_empty() {
  $messages = array();
  $country_required = true;
  $region_required = true;
  $city_required = true;

  if($country_required && Params::getParam('countryId') == '' && Params::getParam('country') == '') {
    $messages[] = __('Country is required!', 'theme');
  }

  if($region_required && Params::getParam('regionId') == '' && Params::getParam('region') == '') {
    $messages[] = __('Region is required!', 'theme');
  }

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_post_url());
    exit;
  }
}

osc_add_hook('pre_item_post', 'check_location_not_empty', 1);

You may also check Backoffice manager plugin.
https://osclasspoint.com/osclass-plugins/backoffice/backoffice-manager-plugin_i49



Problem in Ad Edit Page


try to EDIT ad. without select a city, then redirected to item post page with old ad details



*

MB Themes

Re: Ad Post
« Reply #5 on: November 25, 2020, 08:28:25 PM »
Create one function for publish and one for edit.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #6 on: November 26, 2020, 12:45:34 PM »
Create one function for publish and one for edit.

I need your help, I'm try but not working

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #7 on: November 26, 2020, 03:50:19 PM »
New Ad post Error

Sorry, we don't have any listings with that ID



function check_location_not_empty() {
  $messages = array();
  $city_required = true;

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_edit_url());
    exit;
  }
}

osc_add_hook('pre_item_post', 'check_location_not_empty', 1);

function check_post_location_not_empty() {
  $messages = array();
  $city_required = true;

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_post_url());
    exit;
  }
}

osc_add_hook('pre_item_post', 'check_post_location_not_empty', 1);
« Last Edit: November 26, 2020, 04:35:00 PM by Web »

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #8 on: November 27, 2020, 09:59:41 AM »
@mbthemes

which hook use in item edit page?

*

MB Themes

Re: Ad Post
« Reply #9 on: November 27, 2020, 10:55:57 AM »
@Web
All are listed in docs.
http://docs.osclasspoint.com/Hooks

But pre_item_post is used in add & edit page, alternative would be pre_item_edit

In your case you use function osc_item_edit_url that may miss parameters, so you should have maybe something like this:
Code: [Select]
  osc_item_edit_url(Params::getParam('secret'), Params::getParam('id'));
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #10 on: November 27, 2020, 12:03:15 PM »
@mbthemes

Working this function in item EDIT page

function check_location_not_empty() {
  $messages = array();
  $city_required = true;

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_edit_url());
    exit;
  }
}

osc_add_hook('pre_item_edit', 'check_location_not_empty', 1);


Use the second function then redirected to item post page

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #11 on: November 28, 2020, 08:49:55 AM »
@mbthemes

Any update

*

MB Themes

Re: Ad Post
« Reply #12 on: November 28, 2020, 10:06:50 AM »
@Web
All are listed in docs.
http://docs.osclasspoint.com/Hooks

But pre_item_post is used in add & edit page, alternative would be pre_item_edit

In your case you use function osc_item_edit_url that may miss parameters, so you should have maybe something like this:
Code: [Select]
  osc_item_edit_url(Params::getParam('secret'), Params::getParam('id'));

This was ignored by you.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Web

  • ****
  • 183 posts
Re: Ad Post
« Reply #13 on: November 28, 2020, 12:00:05 PM »
NO

use second function then redirect ITEM POST PAGE



Function 1

function check_item_edit_location_not_empty() {
  $messages = array();
  $city_required = true;

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_edit_url(Params::getParam('secret'), Params::getParam('id')));
    exit;
  }
}

osc_add_hook('pre_item_edit', 'check_item_edit_location_not_empty', 1);

Function 2

function check_item_post_location_not_empty() {
  $messages = array();
  $city_required = true;

  if($city_required && Params::getParam('cityId') == '' && Params::getParam('city') == '') {
    $messages[] = __('City is required!', 'theme');
  }

  if(count($messages) > 0) {
    foreach($messages as $m) {
      osc_add_flash_error_message($m);
    }

    header('Location:' . osc_item_post_url());
    exit;
  }
}

osc_add_hook('pre_item_post', 'check_item_post_location_not_empty', 1);

*

MB Themes

Re: Ad Post
« Reply #14 on: November 28, 2020, 09:00:15 PM »
@Web
Sorry I am lost, osc_item_edit_url will not redirect to publish page.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots