close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

dynamic urls using text field instead of IDs?

Thread began 6/28/2018 6:16 am by tony | Last modified 6/28/2018 10:59 am by Ray Borduin | 31 views | 2 replies |

tony

dynamic urls using text field instead of IDs?

Hello, I would like to create clean urls using dynamic data.
I don't want to create links like this:
www.mysite.com/newsid=1

but I would like to create something like:
www.mysite.com/news=my-news-title

So, I think to add another field to the insert/update form in my admin pages (data assist pages).
The title field would contain the customer entered text (with spaces and accented characters) and the added field would contain a string built converting the text entered in the title field after sanitization (spaces converted to dashes, accented characters converted to simple letters without accents, and so on).
Is there an easy way to do this in dataassist pages?
Thanks in advance.
tony

Sign in to reply to this post

tony

I think I solved this using a custom solution.
I added this code before the WA insert code:
<?php
// funzione pulizia stringa
function CleanString($string)
{
$strResult = str_ireplace("à", "a", $string);
$strResult = str_ireplace("á", "a", $strResult);
$strResult = str_ireplace("è", "e", $strResult);
$strResult = str_ireplace("é", "e", $strResult);
$strResult = str_ireplace("ì", "i", $strResult);
$strResult = str_ireplace("í", "i", $strResult);
$strResult = str_ireplace("ò", "o", $strResult);
$strResult = str_ireplace("ó", "o", $strResult);
$strResult = str_ireplace("ù", "u", $strResult);
$strResult = str_ireplace("ú", "u", $strResult);
$strResult = str_ireplace("ç", "c", $strResult);
$strResult = str_ireplace("ö", "o", $strResult);
$strResult = str_ireplace("û", "u", $strResult);
$strResult = str_ireplace("ê", "e", $strResult);
$strResult = str_ireplace("ü", "u", $strResult);
$strResult = str_ireplace("ë", "e", $strResult);
$strResult = str_ireplace("ä", "a", $strResult);
$strResult = str_ireplace("'", " ", $strResult);
$strResult = str_ireplace("_", " ", $strResult);
$strResult = preg_replace('/[^A-Za-z0-9 ]/', "", $strResult);
$strResult = trim($strResult);
$strResult = preg_replace('/[ ]{2,}/', " ", $strResult);
$strResult = str_replace(" ", "-", $strResult);
return $strResult;
}



?>

and then changed the "alias" field content in the Insert server behaviour to:
<?php echo ((isset($_POST["title_news"]))?CleanString($_POST["title_news"]):""); ?>

This seems to work.

Please let me know if there is a better way to do this.
Thanks again.
tony

Sign in to reply to this post

Ray BorduinWebAssist

I think that works. There is a function iconv() that would replace all accented characters in one line and catch any other characters you might have missed that might be a little cleaner.

<?php
// funzione pulizia stringa
function CleanString($string)
{
$strResult = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$strResult = str_ireplace("'", " ", $strResult);
$strResult = str_ireplace("_", " ", $strResult);
$strResult = preg_replace('/[^A-Za-z0-9 ]/', "", $strResult);
$strResult = trim($strResult);
$strResult = preg_replace('/[ ]{2,}/', " ", $strResult);
$strResult = str_replace(" ", "-", $strResult);
return $strResult;
}

?>

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...