• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Generate a field with unique ID

Generate a field with unique ID 12 years 11 months ago #13502

Hi,

I'm trying to generate a field containing a unique ID. The easy way would be to add something like this to the scripts section's, "On form display" part:

foreach($fields as $i=>$field){
if( $field->name=='uniqueid' ) $fields[$i]->default_value = time();
}

However, I'm looking for a more sophisticated ID so instead of calling the time() function, I'd like to call a function that generates this string. The question is where wold I have the required code? Adding it inside the scripts section leads to an error.

Any help will be greatly appreciated!
Last Edit: 12 years 11 months ago by Orange Creative.
The administrator has disabled public write access.

Re:Generate a field with unique ID 12 years 11 months ago #13506

Doh! :) There is a 'ticket number' field type that does just what I want.
The administrator has disabled public write access.

Re:Generate a field with unique ID 12 years 9 months ago #14224

  • claytoncollie
  • claytoncollie's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 2
I am in need of the same functionality. I can add the "support ticket" hidden field to generate an ID but it is a random number for each submission. is there a way to start with a base number and then increment by 1 for each submission?
The administrator has disabled public write access.

Re: Generate a field with unique ID 11 years 6 months ago #19156

  • dergoog
  • dergoog's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 6
I see that no one really replied with an answer to this one...

I believe the method to use is to take advantage of their php custom code. You should be able to use a chunk of code to get the SubmissionId from the form giving you the unique id number (incremented) for the form's submission.

The only downside is that id is incremented by all form submissions for RS Form - so if you have 3 other forms unrelated to what you're doing your auto increment number won't be sequential to that one form, but all form submissions.

For example - you have a Project Form where you use the unique id for a Project Number. Then you also have a regular contact form.

You submit your first Project to your Project form and get an id number of 1 - before you submit your next project, 4 people post to your contact form. This means your next Project you submit will have an id number of 6. Make sense?

Another way is to create a table in your database that is only for submitting that form and use their feature to submit to that database and then pull your unique id from that table.

I am going to be trying to do this here soon - I'll post my results.
The administrator has disabled public write access.
The following user(s) said Thank You: tessa.stephens, info4060, info03230

Re: Generate a field with unique ID 11 years 6 months ago #19157

  • dergoog
  • dergoog's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 6
As Promised.. here is how I did it - you will need to know your database's login info or be able to create one that you can login into from your server. If anyone knows how to do this using joomla's frame work - please post that!

In your database create a table for your incrementing field - the following SQL will work (recommend you do this using something like phpmyadmin) :
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
 
--
--
 
-- --------------------------------------------------------
 
--
-- Table structure for table `autoincrement`
--
 
CREATE TABLE IF NOT EXISTS `autoincrement` (
  `unique_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique Id Number',
  `form_id` int(11) NOT NULL COMMENT 'Form that requested the unique ID',
  PRIMARY KEY (`unique_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
 
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 

After you create the table, and you know your database's login info - open up your form that you want the have a unique id added.
Add a hidden field on your form called "unique_id" with no value.

On the properties side in PHP Scripts section in the $Post box - use the following code, updating the information with your database's login information:
$hostname_db = "localhost";
$database_db = "YourDatabaseName";
$username_db = "YourDatabaseUserName";
$password_db = "YourDatabasePassword";
$gwc_db = mysql_pconnect($hostname_db, $username_db, $password_db) or trigger_error(mysql_error(),E_USER_ERROR); 
 
$insertSQL = "INSERT INTO `YourDatabaseName`.`autoincrement` (`unique_id`, `form_id`) VALUES (NULL, 11);";             
//the form_id here is arbitrary - if someone knows how to pull the form_id from RS Form please reply with a comment.
 
mysql_select_db($database_db, $gwc_db);
$Result = mysql_query($insertSQL, $gwc_db) or die($insertSQL." ".mysql_error());
$id = mysql_insert_id($gwc_db);
 
//The following code makes it so your number has leading zeros - there is probably a more elegant way to do this - but it's late and I'm tired :)
if ($id < 10) { $id = "0000".$id; } elseif ($id < 100) { $id = "000".$id; } elseif ($id < 1000) { $id = "00".$id; } elseif ($id < 10000) { $id = "0".$id; }
  $_POST['form']['unique_id'] = $id; 
//Be sure your form has the hidden item unique_id

So what happens as a result of this is we have an independent table dedicated to our form. It only has two fields a unique_id field and a form_id field - both are set to be numbers. I don't know how to pull the form_id from rs form, so I put in an arbitrary value.

With this code added to your form, now when someone submits the form, it will update the value of the hidden field to the number of your unique_id. In this case I determine the length count of the unique id and put leading zeros in front of it (ie 00001, 00010, 00100, etc)

In your form's responses and excel sheet you will have access to the updated unique_id.

You can rename any variables in this - just be sure you update all the instances across the board.

Hope this helps someone!
Last Edit: 11 years 6 months ago by dergoog.
The administrator has disabled public write access.
The following user(s) said Thank You: tessa.stephens, info4060

Re: Generate a field with unique ID 11 years 6 months ago #19180

  • amit2310
  • amit2310's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
if we use mapping then we can have an unique_id or ticket_id column in the mapped table. How can we fetch that id using php script
The administrator has disabled public write access.

Re: Generate a field with unique ID 11 years 4 months ago #20459

  • dergoog
  • dergoog's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 6
I was just browsing looking for a way to load database sourced values into a form field and saw your question - not sure what you're intending for the long run... can you elaborate?
The administrator has disabled public write access.
The following user(s) said Thank You: info4060
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!