MsKazza Posted February 23, 2016 Share Posted February 23, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/ Share on other sites More sharing options...
ginerjm Posted February 23, 2016 Share Posted February 23, 2016 What's a slug? People usually post the Pertinent code here using the proper code tags, ie, php and /php wrapped in square brackets. Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531368 Share on other sites More sharing options...
MsKazza Posted February 23, 2016 Author Share Posted February 23, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531373 Share on other sites More sharing options...
ginerjm Posted February 23, 2016 Share Posted February 23, 2016 Sounds like you are asking for real-time db updates to happen as the user adds input. Sounds like an AJAX call to me. Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531376 Share on other sites More sharing options...
MsKazza Posted February 23, 2016 Author Share Posted February 23, 2016 (edited) 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 February 23, 2016 by MsKazza Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531378 Share on other sites More sharing options...
ginerjm Posted February 23, 2016 Share Posted February 23, 2016 I have no idea what you want. Good luck Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531387 Share on other sites More sharing options...
maxxd Posted February 23, 2016 Share Posted February 23, 2016 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); Quote Link to comment https://forums.phpfreaks.com/topic/300865-create-textbox-value-from-previous-entry/#findComment-1531388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.