Jump to content

create textbox value from previous entry


MsKazza

Recommended Posts

Hi,

I've created a page that adds a product to our database, one of the fields is a 'slug' which i usually create by running a mysql snippet once the product has been added (please see attached file).  I was hoping if someone might be able to tell me if there is a way to do the same thing but in php when the user has entered the product name then tabs or clicks into slug the script automatically populates the field based on the product name entered and the rules as per the sql file.

 

Hope i've explained clearly.

thanks,

 

MsKazza

create slug.txt

Link to comment
Share on other sites

this is what my links look like to make them userfriendly : domain.ie/product?name=t-shirts/valueweight-t

 

the 'slug' (not sure where that name came from, its just what i know it as) is the part after name= , makes the search engines like the product names more.  Usually I run the following sql query on the database to create these 'slugs' as don't want user to make them.

 

 UPDATE products 
INNER JOIN sub_categories ON sub_categories.id = products.sub_category 
SET
    slug = replace(trim(lower(concat(sub_categories.subcat_name,'/',products.product_name))), ' ', '-');

UPDATE products SET
    slug = replace(slug, '&', '-');

UPDATE products SET
    slug = replace(slug, '---', '-');

UPDATE products SET
    slug = replace(slug, ''', '');

as explained (hopefully clearly) in above post I want to try find some way to do this in php as the user enters the product information.

 

thanks.

Link to comment
Share on other sites

no its part of an insert statement, its not already in db, i just want the second box to somehow rearrange the 'slug' text like in the sql statement, adding the category and product name, removing spaces, etc.

 

e.g.

product name :  (text box here)

 

category : (select box here)         subcategory : (select box here)

 

slug : ([get subcategory from user selection]\[altered product name from user selection])   - user can't edit this box its automatically generated.

 

before it inserts into db

Edited by MsKazza
Link to comment
Share on other sites

You would do the string replacement in your form processing method or function. Basically, you'll be doing what you're currently using SQL to do, but in PHP and before the record is inserted or updated in the database.

 

Something along the lines of:

$slug = $_POST['userSlug'];

$slug = str_replace(array(' ','&','---'),'-',$slug);
$slug = str_replace(array('"',"'"),'',$slug);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.