close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Slug from Title

Thread began 2/12/2013 3:32 am by Daryl | Last modified 2/12/2013 6:16 am by Dave Buchholz | 500 views | 2 replies |

DarylBeta Tester

Slug from Title

I have been for years trying to get my head round mod_rewrite and Pretty URLs, and the recent email and Davids example has given me the bug.

I am trying to get my head round 'slugs'. I understand the concept and why we need them, but am trying to figure out how to get DataBridge to do this for me.

I have a Title, Introduction and Content field in a form (as well as date, user etc), and then want the Databridge form to send a slug to the slug column which would be a title with hyphens instead of spaces and special characters removed. I assume that this is generated by the title form field but am not sure how I a) alter the title and b) how I get the form to insert the title in to the title column and the modified version into slug as it will be coming from the same form field.

I have been reading this link which gives me the function;

php:
function create_slug($string){

   $string = preg_replace( '/[«»""!?,.!@£$%^&*{};:()]+/', '', $string);
   $string = str_replace( "'", '', $string);
   $string = strtolower($string);
   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
   return $slug;
}
$slug = create_slug($title);



But Im not sure where to put this and how to integrate it into an insert form.

Thanks in advance

Sign in to reply to this post

DarylBeta Tester

OK....

I have figured out how to submit one form field to two different columns;

Open the insert record behaviour and then choose the dynamic value as the same form field.

php:
<?php echo ((isset($_POST["title"]))?$_POST["title"]:""); ?>



Then to remove special characters, make lowercase and replace spaces with hyphens, I changed the lightening bolt value to look like the following

php:
<?php echo (preg_replace('/[^A-Za-z0-9-]+/''-'str_replace"'"''preg_replace'/[«»""!?,.!@£$%^&*{};:()]+/'''strtolower((isset($_POST['title']))?$_POST['title']:""))))); ?>



I'm not sure if this is the most efficient way, and I'm willing to be told, but it works!

Sign in to reply to this post

Dave BuchholzBeta Tester

Daryl,

I store the slugs in their own field in the db table and wrap the insert field with a function like so:


php:
"|" . "".((isset($_POST["slug"]))?i8_UrlParameter($_POST["slug"]):"")  ."" . "|"
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...