Forum Moderators: coopster

Message Too Old, No Replies

Add a Prefix to Form Field Entry

         

piskie

11:35 am on Sep 29, 2006 (gmt 0)

10+ Year Member



I am storing product details in a MYSQL Table.
This is to hold Multiple Merchants.
Each Product code must be Unique.

To achieve this but still allow each Merchant to freely assign his own Product Code system I need to prefix the entered Product Code with the appropriate Merchant Code.

The Merchant Admin uses php forms and the product code field is:
<input type="text" name="code" id="code" value="<?php echo KT_escapeAttribute($row_rsstock['code']);?>" size="32" />

The insert function in the head of the page is:
$ins_stock->addColumn("code", "STRING_TYPE", "POST", "code");

For example I would like a product code ABC123 entered by Merchant D100 to automatically become:
D100-ABC123
I also need to prevent the automatically inserted prefix being overtyped in the form field.

As I am very much a beginner in PHP & MYSQL, a simple expression would be preferred with enough info for me to use with limited knowledge.

Thanks in advance.

barns101

11:42 am on Sep 29, 2006 (gmt 0)

10+ Year Member



Why not store the Merchant Code as a session variable when the merchant logs in and then prepend the value to his Product Code when adding it to the database?

piskie

9:51 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



The Merchants Code appears in the page already, so doesn't need to be stored in a session variable. I just need to know how to "Append" it to a Form Field Input. The Form is quite complex with a mixture of Text fields and hidden fields plus several image file uploads with resizing and renaming.

All that works OK, but I don't know how to put "ABC123" in front of the "Product Code" text input field without the risk of overtyping.

henry0

10:35 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could pass the prefix via another hidden field, or a var or.....
And then do a concatenation

For example:

$prefix = "XD-678-";
$prod_code= “ABC123”;

$last_step= $prefix.$prod_code;

$last_step will deliver
XD-678-ABC123