WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7 - Generating Reference Number (21 posts)

  1. schabe23
    Member
    Posted 4 years ago #

    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?

  2. schabe23
    Member
    Posted 4 years ago #

    No ideas anyone?! I'm going mad over this.

  3. mark_weston
    Member
    Posted 4 years ago #

    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.

  4. AMCD
    Member
    Posted 3 years ago #

    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!

  5. webjunk
    Member
    Posted 3 years ago #

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

  6. AMCD
    Member
    Posted 3 years ago #

    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!

  7. webjunk
    Member
    Posted 3 years ago #

    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.

  8. AMCD
    Member
    Posted 3 years ago #

    Would rather it be outside the plugin so future updates don't remove the functionality...

  9. webjunk
    Member
    Posted 3 years ago #

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

  10. AMCD
    Member
    Posted 3 years ago #

    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.

  11. musicdesigns
    Member
    Posted 3 years ago #

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

    I really want this function

  12. AMCD
    Member
    Posted 3 years ago #

    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!

  13. musicdesigns
    Member
    Posted 3 years ago #

    That is amazing!!!!

    Wow!

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

    (Which is perfect)

  14. AMCD
    Member
    Posted 3 years ago #

    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...)

  15. musicdesigns
    Member
    Posted 3 years ago #

    No that's perfect.

    So clever. This would have taken me ages!

    How do I create a "hideme" span in my CSS?

  16. AMCD
    Member
    Posted 3 years ago #

    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.

  17. musicdesigns
    Member
    Posted 3 years ago #

    Oh great, thanks.
    Where should I place this code? (Sorry I'm so bad with coding)

  18. musicdesigns
    Member
    Posted 3 years ago #

    Oh It's OK I've worked it Out.

    Thanks for All your help!

  19. musicdesigns
    Member
    Posted 3 years ago #

    AMCD, I've got a similar requirement.

    Do you know if there's a suitable php script that would also send a predetermined set of charecters.

    What I need to do is add to the email a reference number that is from a list. And then when the next form is submitted it sends the reference number that's second in the list etc.

    SO..

    instead of sending them a random code it will send them the first item on the list, then the next will receive the second, the next the third and so on.

    This is a really hard one, can't get my head around it

  20. laptopdesktop
    Member
    Posted 3 years ago #

    Can someone help me to add a counter using quiz ?
    I dont know really about the code, but it should be like this

    a = 1
    b = 1 + a
    re-write b = a
    submit a back to the database.

  21. nevilletietz
    Member
    Posted 3 years ago #

    This was fantastic! Thanks AMCD!!

Topic Closed

This topic has been closed to new replies.

About this Topic