LISE API Auto Generate URL from Frontend Form

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

LISE API Auto Generate URL from Frontend Form

Post by webform »

I'm trying to trigger a GenerateSlug for items submitted from a frontend form.
I have this code in my UDT, but the URL field remains empty:

Code: Select all

$obj->slug = LISE\api::GenerateSlug($params['title'], 'LISEINSTANCE');
I'm guessing the field name is wrong, and changed the code to:

Code: Select all

$obj->url = LISE\api::GenerateSlug($params['title'], 'LISEINSTANCE');
And then i do get a value in the URL field, althought it is the string "--error--".
Looking in the class.api.php file it looks like i need 4 parameters ($instance_name, $title, $iid, $cid) and not only the two $title and $instance_name.
Is it possible to generate an URL from a Frontend Form or do i have to make my own custom solution?

Code: Select all

$obj->url = 'myPrefix/' . $params['title'];
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: LISE API Auto Generate URL from Frontend Form

Post by webform »

I couldn't figure out how to get the GenerateSlug API to work, so i did a work around where i generates the slug based on an uniq serial field and the title field:

Code: Select all

/**
 * Load wanted LISE instance, where you wan't to save items.
 * If instance can't be loaded, it will silently return.
 */
$mod =  \cms_utils::get_module('MYLISEINSTANCE');
if(!is_object($mod))
  return;

/**
 * now use the new LISE API
 */

$alias = LISE\api::GenerateAlias($params['title'], 'MYLISEINSTANCE');

/**
 * preparing for the item url
 */
$title = $params['title'];
$title = mb_strtolower($title);
$title = str_replace(" ", "-", $title);
$title = preg_replace("/[^ÆØÅA-Zæøåa-z0-9\-]/","", $title);

/**
 * Initialize item with identifier 'alias', $params['title'] comes from FormBuilder.
 * Do duplication check with 'item_id', silently return, if item already in database.
 */
#$alias = munge_string_to_url($params['title'], true);
$obj = $mod->LoadItemByIdentifier('alias', $alias);

if($obj->item_id > 0)
  return;

/**
 * Fill previously initiated LISEItem object with values from form submission.
 * NOTICE: All params that are not known by LISEItem object are going to be ignored.
 */
$obj->title = $params['title'];
$obj->alias = $alias; # we already have one
#$obj->slug = LISE\api::GenerateSlug($params['title'], 'MYLISEINSTANCE'); # Doesn't seem to work
$obj->url = 'myPrefix/' . $params['url_id'] . '-' . preg_replace('/-+/', '-', $title);

foreach($params as $key => $value) {
  if(isset($obj->fielddefs[$key])){
    if($value != "[unspecified]"){
      $obj->$key = $value;
    }
  }
}

/**
 * Save this object to database by using LISE API.
 */
$mod->SaveItem($obj);
Post Reply

Return to “Modules/Add-Ons”