I would like to be able to have members create codes, these codes are made of text based on drop down and should contain a numerical value that must be unique (with Channel Forms Grid (safecracker)) and increment by one with each new entry. Does any one know of a way to do this, the initial entry needs be to be dynamically generated and written to the DB entry field as static entry on save. Many thanks for any advise.


3 Answers 3


You could write an extension calling the ee()->extensions->call('channel_form_submit_entry_start', $this);


In your extension you then do the unique (auto increment) value by using the DB class to check for uniqueness.

Example code for the auto increment would be something like:

` $auto_increment = 1; $query = ee()->DB->query('SELECT field_id_x FROM exp_channel_data' WHERE field_id_x = $auto_increment LIMIT 1);

if($query->num_rows() != 0 ) { $auto_increment = $query->row()->field_id_x + 1; } `

You can also do more of the logic in MYSQL like so:

`$query = ee()->DB->query('SELECT (COUNT(*)+1) AS auto_increment FROM exp_channel_data WHERE channel_id = "y" GROUP BY channel_id');

$auto_increment = $query->row()->auto_increment; `

  • Would love to know how to do that :)
    – user2929
    Commented May 15, 2014 at 16:34

Reatile's answer is good for what you outlined in your question, but one possible consideration and possibly easier to implement is to make use of the {entry_id}. This automatically is a unique numerical value which increases by 1 every time a new entry is created. You could also prepend some other identifier like 'sku{entry_id}', which would then render output to 'sku598'.

One possible issue is if you need the number to be strictly sequential within it's own channel/category. Using the entry_id will mean there will be gaps between numbers if there is an entry created outside of that particular use. However, this may or may not matter depending on your particular needs.


If you create entrys with the same title name, the url_title field will contain the title name + a numerical value (auto increment).

dont know if you can use it to your advantage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.