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!