Forums

printing unique id on thankyou page

moryali 22 Dec, 2008
hi,
I am trying to Print a unique id on the thank you page after sending a form,so that the user will be able to use it for future reference.

I can't seem to succeed would appreciate some help,

Thanks,
Ilan
GreyHead 22 Dec, 2008
Hi Ilan,

Please say a little bit more about the problem:[list]
  • Is it creating the id?
  • Or making sure it's unique
  • Or showing it on the thank you page?
  • [/list]
    ChronoForms creates a unique id for every record saved in the database - but it's a bit long and not memorable e.g. uid = IM2I1NmJlYjRmYjMx There's also a record is 1,2, 3 . . . etc. which is simpler but not good to use as it leaves the possibility tha someone will try to get records based on guessing the sequence.

    Here's a function that I wrote for an application to generate short id numbers using a pattern - the defult is AA9999A so you get results like CF3672G which are readable.
    	/*
    	 * 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;
    	}
    This has about 90m variants but there is still a chance of a duplicate so you'd need to run a check on the database to be absolutely certain.

    To use a code like this - create it in the form html box, add it to the form in a hidden field, then use the hidden field name to display it in the email template or use an echo statement to show the value on the thank you page.

    Bob
    GreyHead 22 Dec, 2008
    Hi Ilan,

    Here's another example from a different project - this one creates a coupon code that is a random strign but includes the uniqueness check,
    <?php
    if ( !$coupon ) {
        // create a new coupon and check that it is unique.
        do {
            $coupon = createCoupon();
            $sql = "
                SELECT
                    COUNT(*)
                    FROM #__some_table
                    WHERE coupon = ".$database->quote($coupon).";";
            $database->setQuery($sql);
        } while ( $database->loadResult() != 0 );
    }
    . . . 
    /*
     * function createCoupon
     * param integer length = length of coupon string
     * return string coupon
     */
    function createCoupon($length='6')
    {
        $possible = "0123456789bcdfghjkmnpqrstvwxyzABCDEFGHJKLMNPQRSTUWXYZ";
        $i = 0;
        while ( $i <= $length ) {
            $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
            // we don't want this character if it's already in the password
            if ( !strstr($password, $char) ) {
                $coupon .= $char;
                $i++;
            }
        }
        return $coupon;
    }

    Bob
    moryali 22 Dec, 2008
    Hi Bob,
    Thank you very much for your reply,
    I think the codes are very useful and I will use the first one with your permission,
    my problem is displaying it on the thank you page.
    I installed the mod_php and published it on the content page so I will be able to insert php code in the content page, I can't seem to retrieve the current uid from the form submitted or any other field.
    As I am quite new to php there is probably a simple solution which I cant seem to figure out.

    Thanks again,
    Ilan
    GreyHead 22 Dec, 2008
    Hi Ilan,

    What do you want to show on your Thank-you page? The simplest way of creating a thank you page in ChronoForms is to put some html into one of the OnSubmit boxes (probably OnSubmit After) and *not* to use a ReDirect URL.

    If you have the uid in a hidden input named 'uid' then you can display it like this:
    <p>Thank you for completing our form.</p>
    <p>Your Form ID is <?echo JRequest::getString('uid', '', 'post'); ?>. 
    Please copy this and keep it sae to access your data in the future.</p>

    Bob
    moryali 22 Dec, 2008
    Hi and thanks again for your answer,
    I tried putting the code as you said and I got the following errors:


    Warning: reset() [function.reset]: Passed variable is not an array or object in /(Domain Path)/includes/joomla.php on line 3992

    Warning: Variable passed to each() is not an array or object in /(Domain Path)/includes/joomla.php on line 3994

    Thank you for completing our form.

    Your Form ID is
    Fatal error: Class 'JRequest' not found in /(Domain Path)/components/com_chronocontact/chronocontact.php(537) : eval()'d code on line 2

    I am using joomla 1.015 if it is of any help.

    Thanks again,
    Ilan
    GreyHead 22 Dec, 2008
    Hi moryali,

    The Joomla 1.,0.x is the problem - all the code I gave you is for Joomal 1.5 . . . :-(

    Try this version in the form html adn see if the errors go away:
    <p>Thank you for completing our form.</p>
    <p>Your Form ID is <?echo $_POST['uid']; ?>.
    Please copy this and keep it safe to access your data in the future.</p>


    Bob
    moryali 23 Dec, 2008
    Thanks again,
    I think I need to start over because I am still getting the error messages.
    The moment Insert php into my form code I get the following error while trying to load the form:
    Parse error: syntax error, unexpected '<' in /(domain Path)/mambots/content/chronocontact.php(201) : eval()'d code on line 37

    my basic form code without the uid hidden value is:
    <table cellspacing="1" cellpadding="1" border="1" style="width: 450px; ">
        <tbody>
            <tr>
                <td bgcolor="#404040">Name*:</td>
                <td bgcolor="#404040"><input type="text" name="name" maxlength="100" style="width: 250px;" /></td>
            </tr>
    <tr>
                <td bgcolor="#404040">Position*:</td>
                <td bgcolor="#404040"><input type="text" name="position" maxlength="100" style="width: 250px;" /></td>
            </tr>
            <tr>
                <td bgcolor="#404040">E-mail*:</td>
                <td bgcolor="#404040"><input type="text" name="email" maxlength="100" style="width: 250px;" /></td>
            </tr>
            <tr>
                <td bgcolor="#404040">Phone Number*:</td>
                <td bgcolor="#404040"><input type="text" name="phonenumber" maxlength="50" style="width: 250px;" /></td>
            </tr>
     
      <tr>
                <td bgcolor="#404040">Delivery Location*:</td>
                <td bgcolor="#404040"><input type="text" name="deliverylocation" maxlength="50" style="width: 250px;" /></td>
            </tr>
      <tr>
                <td bgcolor="#404040">Delivery Date*:</td>
                <td bgcolor="#404040"><input type="text" name="deliverydate" maxlength="50" style="width: 250px;" /></td>
            </tr>
            <tr>
                <td valign="top" bgcolor="#404040">Order Details*:</td>
                <td bgcolor="#404040"><textarea name="details" style="width: 250px;" rows="12"></textarea></td>
            </tr>
            <tr>
                <td >* = Required fields</td>
                <td style="float: right;" bgcolor="#404040"><input type="submit" name="submit" value="Submit" />
    
    
    ?>
    </td>
            </tr>
        </tbody>
    </table>
    


    I am sure I am doing something wrong while inserting the uid hidden value.

    I will try and simplify it with 2 questions:
    1. What code do I use to insert the hidden value? (all my trials didn't succeed)
    2. how do I display the value after submitting the form?

    I thank you very much for your help, and apologize for being a bit of a nuisance

    Ilan
    Max_admin 23 Dec, 2008
    Ilan, is this V3.0 stable of CF ? what id are you trying to get ?

    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    moryali 24 Dec, 2008
    Hey Max,
    I am using version 2.3.9.
    I checked the download section, I see it is the latest release for joomla 1.015
    my site is joomla 1.015

    I am trying to get any unique ID for future reference, it can be the automatic generated UID.
    Ilan
    GreyHead 24 Dec, 2008
    Hi moryali,

    I see that error is in the PlugIn code - please don't do development using the plugin, it just makes things to complicated. Develop using the page that is linked to in the Forms Manager.

    Line 37 of your code is
        ?>
    whic isn't valid html - that's what is causing the immediate problem.

    And I think I'm correct in saying that the uid field wasn't added to ChronoForms until v3.0 - but Max may remember better that I do.

    Bob
    Max_admin 24 Dec, 2008
    Hi,

    try to view one of the records saved in your form and see if the page has uid record ? its usually just after the cf_id, I mean when you view the record details page!

    Regards
    Max
    Max, ChronoForms developer
    ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
    ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
    moryali 24 Dec, 2008
    Hi and thanks for your replies,
    here are my answers:

    1. the ?> remained from one of my experiment to insert a hidden value, I removed it but I still get the same error messages.
    2. I do have a uid when I check the records saved from the form.


    is there version 3 for joomla 1.015 or is it only for joomla 1.5?

    Ilan
    GreyHead 24 Dec, 2008
    Hi moryali,

    Inserted php should look like
    <?php
    echo "some message";
    ?>
    Please post an example of the form html with PHP that causes problems.

    Version 3 is only for Joomla 1.5.x - is there any reason why you can't upgrade - just curious?

    Bob
    This topic is locked and no more replies can be posted.