Support » Plugins and Hacks » Contact Form 7 – Generating Reference Number

  • Hi there,

    Basically I’m creating a site for a talent agency that wants to be able to register interest from each act using a contact form. Pretty simple to do that, but they require a unique reference number to be generated for each enquiry that can be used throughout the entire transaction.

    Now I would do this using a .db file (it doesn’t have to be secure) and php code from a regular contact form, however, I’m in love with Contact Form 7 and I’d rather just add to it’s collection of shortcodes to do so.

    Having a bit of trouble though, anyone done something similar and has a clue where to start?

Viewing 15 replies - 1 through 15 (of 20 total)
  • No ideas anyone?! I’m going mad over this.

    Have you looked at the wpcf7_before_send_mail hook?

    http://wordpress.org/support/topic/plugin-contact-form-7-insert-contact-name-and-email-in-database-after-successful-submission?replies=19

    You might be able to add another field for the reference. An easy way to get a unique reference is base it on the date & time.

    Anyone figure out how to do this? I would like to include a unique reference number in the subject line of emails sent by Contact Form 7

    Your help is appreciated!

    Would use the PHP Time function and make that a hidden field into the form.

    How would you then go writing that into the plugin? Add a function to the themes function.php? If thats the method are there any tutorials or could someone let me know how this is done and tied into the form?

    Thanks!

    Do not have time right now to look at the exact but basically you can edit the form template (I think its in the CF7 functions.php)
    and enter a new field and make it hidden. So like:
    <input type=”text” name=”reference” value=”<?php echo time(); ?>” />

    This should put a UNIX timestamp in. Could get fancier and remove the leading digits or change to normal time formats. If you have real heavy traffic you might get duplicates but its to the second so would be rare. And if you really had to could add a random number to the end.

    Would rather it be outside the plugin so future updates don’t remove the functionality…

    Sorry…Maybe you could give a donation to the author and he could add this as a feature within the plugin.

    Discovered a handy plugin that allows custom short code to be injected into the form: ‘contact-form-7-dynamic-text-extension’. Created a function in the themes function.php that generates a reference ticket. I then pull that value into a text input in the form and used css to hide that field.

    Im developing locally with no mail server installed so I can only assume that this works… Dont see why it wont.

    AMCD – can you break it down in simple terms how to do this please?

    I really want this function

    In your functions.php you will need a function to generate the random string:

    /* Generate Quote Ticket */
    function genTicketString() {
        $length = 8;
        $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for ($p = 0; $p < $length; $p++) {
            $string .= $characters[mt_rand(0, strlen($characters)-1)];
        }
        return $string;
    }
    add_shortcode('quoteticket', 'genTicketString');

    Next make sure you’ve installed the contact-form-7-dynamic-text-extension plugin and add the dynamic field into the form. This is what I used (wrapping it in a span to hide the input with css):

    <span class="hideMe">[dynamictext ticket "quoteticket"]</span>

    “quoteticket” calls the function populates the input with a random string (set the length etc in the function)

    and finally add the ticket to your email body with [ticket]

    Hope that helps!

    That is amazing!!!!

    Wow!

    will that only generate an 8 charecter alpha/numeric code?

    (Which is perfect)

    Yes that is what it will do…

    change the $length = 8; to whatever you want and you can add additional characters to the $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" string if you want as well. (ie !@#$% or lowercase abcdef etc…)

    No that’s perfect.

    So clever. This would have taken me ages!

    How do I create a “hideme” span in my CSS?

    I used the negative text-indent trick to push it out of the visible width of the browser:

    .hideMe{
      display:block;
      position:absolute;
      text-indent:-9999px;
      float:left;
    }

    Of course IE7 and below dosent like this so in my IE conditional css file pushed it out using margin:

    .hideMe{
      margin:0 0 0 -9999px;
    }

    Don’t know if this is the best method but its working… Would be better if Contact Form 7 supported hidden fields, maybe in the future it will.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Contact Form 7 – Generating Reference Number’ is closed to new replies.