Help please, IdevAffiliate and Chronoforms integration.

fumla 28 Jan, 2009
I need urgently help to get my problem solved, and please have in mind, you wont find someone more stupid than me to do programming.

I have chronoform installed, works perfekt, also connected it ot the DB works perfect. Now I installed idevaffiliate, which also works and I integrate the code from ideaffiliate to the forms.

However, I need to have a order ID generated which connectect the incomming applications from chronoform to my affiliate sys.

The problem is, I don't know how to generate a unique ID (already saw an example here but don't get it) and then get this Uniqe ID passet to
the variable of the affiliate system.

I know for sure this is peace of cake for all you hard core coders out there but for me it is mission impossible!

Im willing to pay for a fast solution.

The image string I got from the affiliate sys looks like this :

<img border="0" src="http://www.yourdomain.com/affiliate/sale.php?profile=44&idev_leadamt=1.00&idev_ordernum=XXX" width="1" height="1">

This is the part where the 3 XXX are : &idev_ordernum=XXX : where I need the unique ID
GreyHead 28 Jan, 2009
Hi fumla,

There are a couple of pieces to this. It's fairly easy to get - for example - the primary key from your database and use that. However, this isn't secure, people see affiliate code 448 and say . . . let's try 449 then and 450 . . . It's better to use random codes.

It's also easy to generate a random code - you can see an example in the ChronoForms autogenerated code. But you need to check that it's unique - the chances of getting the same code twice are small but they aren't zero. Here's a couple of code snippets that will do this:
<?php
$db =& JFactory::getDBO();
do {
  $affiliate_id = generateIdent();
  $query = "
    SELECT COUNT(*)
      FROM #__some_db_table
      WHERE `affiliate_id` = $affiliate_id ";
  $db->setQuery($query);
} while ( $db->loadResult() > 0 );
/**
 * function to generate a random alpha-numeric code
 * using a specified pattern
 *
 * @param $pattern string
 *
 * @return string
 */
function generateIdent($pattern='AA9999A')
{
   $alpha = array("A","B","C","D","E","F","G","H",
    "J","K","L","M","N","P","Q","R","S","T","U","V","W",
    "X","Y","Z");
  $digit = array("1","2","3","4","5","6","7","8","9");
  $return = "";
  $pattern_array = str_split($pattern, 1);
  foreach ( $pattern_array as $v ) {
    if ( is_numeric($v) ) {
      $return .= $digit[array_rand($digit)];
    } elseif ( in_array(strtoupper($v), $alpha) ) {
      $return .= $alpha[array_rand($alpha)];
    } else {
      $return .= " ";
    }
  }
  return $return;
}
?>
at the end you'll have a unique code in $affiliate_id

You can use this code in the OnSubmit boxes to add to the records.

Bob

Later: corrected an error in the function name
fumla 28 Jan, 2009
Thank you very much for your help... it isn't that important to get the ID 100% unique since each time a affiliate sale is generated it needs some time before it will be approved.

However, just to get you, then the code you gave as an exampl I have entered into CF "On Submit code - before sending..."

Now you say I will have the uniqe ID each time a new sale is made.

But how do I get this ID into this string :
<img border="0" src="http://www.yourdomain.com/affiliate/sale.php?profile=44&idev_leadamt=1.00&idev_ordernum=XXX" width="1" height="1">

For instant lets say the unique number which is generated for $affiliate_id is 444

What is the parameter I need to put in where the XXX is ( &idev_ordernum=XXX) I guess their must be a variabel which graps the 444 and insert it so that the string looks like this. &idev_ordernum=444

Hope you can follow meπŸ™‚
GreyHead 28 Jan, 2009
Hi fumla,

All understood - but where do you generate the affiliate string?

Bob
fumla 28 Jan, 2009
The code I get directly from idev affiliate, it says I just have to
-------------------
Place the following code into your lead confirmation page. This is the page the customer sees after completing your lead form.

<img border="0" src="http://www.yourdomain.com/affiliate/sale.php?profile=44&idev_leadamt=1.00&idev_ordernum=XXX" width="1" height="1">

Description:
Adding a lead number is optional. To use a lead number, simply replace the XXX with an actual lead number (variable). It is useful for cross-referencing a customer lead to an affiliate commission. To use this option, you must have a unique identifier of some sort available in your lead form. The traditional use is an actual lead number. If you don't have a lead number built-in to your lead form, you can of course use something like a last name or email address. If you aren't going to attach a lead number to the commission record, alter the above code by removing &idev_ordernum=XXX before placing it.

-------------------------------------------------------------
Also I get this error if I enter the code you gave me:

Fatal error: Call to undefined function generateIdent() in /home/yourdomain.com/public_html/components/com_chronocontact/chronocontact.php(371) : eval()'d code on line 4

I entered it as following with the Β΄ and without it, bith gave the same result and the table name is the one in the DB

<?php
$db =& JFactory::getDBO();
do {
$affiliate_id = generateIdent();
$query = "
SELECT COUNT(*)
FROM # `jos_chronoforms_ccount`
WHERE `affiliate_id` = $affiliate_id ";
$db->setQuery($query);
} while ( $db->loadResult() > 0 );
/**
* function to generate a random alpha-numeric code
* using a specified pattern
*
* @param $pattern string
*
* @return string
*/
function generateCvIdent($pattern='AA9999A')
{
$alpha = array("A","B","C","D","E","F","G","H",
"J","K","L","M","N","P","Q","R","S","T","U","V","W",
"X","Y","Z");
$digit = array("1","2","3","4","5","6","7","8","9");
$return = "";
$pattern_array = str_split($pattern, 1);
foreach ( $pattern_array as $v ) {
if ( is_numeric($v) ) {
$return .= $digit[array_rand($digit)];
} elseif ( in_array(strtoupper($v), $alpha) ) {
$return .= $alpha[array_rand($alpha)];
} else {
$return .= " ";
}
}
return $return;
}
?>
GreyHead 28 Jan, 2009
Hi fumla,

Sorry, I copied the code from two different places - change the function generateCvIdent($pattern='AA9999A') to function generateIdent($pattern='AA9999A')

If you put this in one of the OnSubmit boxes then you would genreate the image code with
<img border="0" src="http://www.yourdomain.com/affiliate/sale.php?profile=44&idev_leadamt=1.00&idev_ordernum="<?php echo $affialate_id; ?>" width="1" height="1">
HTML in the OnSubmi box will display in the Joomla page after the form is submitted.

Bob
ashwinuae 13 Apr, 2009
Hi Bob!

First of all, thats one amazing component you have out there! Great work! :wink:
Ok, now onto the problem. I have chrono installed, evrything working perfectly, data gets emailed and stored into table. Now I need the form to generate a Unique ID very similar to the pattern explained above, and store the same in the table. I used the same code with field name changes:
<?php
    $db =& JFactory::getDBO();
    do {
      $tcc_id = generateIdent();
      $query = "
        SELECT COUNT(*)
          FROM # `jos_chronoforms_application`
          WHERE `tcc_id` = $tcc_id ";
      $db->setQuery($query);
    } while ( $db->loadResult() > 0 );
    /**
    * function to generate a random alpha-numeric code
    * using a specified pattern
    *
    * @param $pattern string
    *
    * @return string
    */
    function generateIdent($pattern='AA9999A')
    {
       $alpha = array("A","B","C","D","E","F","G","H",
        "J","K","L","M","N","P","Q","R","S","T","U","V","W",
        "X","Y","Z");
      $digit = array("1","2","3","4","5","6","7","8","9");
      $return = "";
      $pattern_array = str_split($pattern, 1);
      foreach ( $pattern_array as $v ) {
        if ( is_numeric($v) ) {
          $return .= $digit[array_rand($digit)];
        } elseif ( in_array(strtoupper($v), $alpha) ) {
          $return .= $alpha[array_rand($alpha)];
        } else {
          $return .= " ";
        }
      }
      return $return;
    }
    ?>


And also created a hidden field in the form:
<input type='hidden' name='tcc_id' value='' />


But unfortunately nothing seems to work. I tried the steps mentioned in similar forum posts, i.e. changing run order and changing save order to before/after email but to no avail. Please keep in mind that I'm totally new to PHP... Is there some step that I'm missing here?

Thanks in advance!
Regards
GreyHead 13 Apr, 2009
Hi ashwinuae,

Max's component, I just help out here.

I think the code is missing a line to do something with the code. Try adding this line:
    } while ( $db->loadResult() > 0 );
JRequest::setVar('tcc_id', $tcc_id, 'post'); // <-- add this line

Bob
ashwinuae 13 Apr, 2009
Wow! That was lightning fast response! πŸ˜€

Well, I must say that the support you provide is too good! I hit another issue yesterday with the Anti-spam image not loading, and a quick search solved the problem! Remember the issue of stray characters in the chronoverification.php file? That one...

Well this ones another successful solution added to the list! That extra line did the trick! IT WORKSSS!!! THANKS A TON!

Right now, the code is pasted into the OnSubmit Before sending Email box, Saving Data is set to Before Email under Autogenerated code and OnSubmit Block is placed higher than Autogenerated Block in RunOrder.

Once again, thanks a zillion times! :mrgreen:
Loadsa respect & regards...
This topic is locked and no more replies can be posted.