-1

I'm a newbie to web designing. I'm using contact form 7 to create a registration form for our conference.

All I wanted to do is, I need to give a unique id for all of them after they have registered for the conference and the further forms should be identified using this unique id.

So far, I have installed contact form 7 and contact form dtx for this purpose and I have tried Koen de Bakker solution of generating a random number.

But it's slightly different from what I want, since it changes the random number for each refresh.

What I'd like is:

  1. An unique number like "17ICLAA001,..." should be generated for each form submission.

  2. Send the unique number to the applicant after successive submission of the form.(I hope this can be easily done once the shortcode is done).

  3. Editing the form using the unique id.

Any help will be much appreciated. Thank you.

Community
  • 1
  • 1

2 Answers2

0

Correct way to generate a unique and progressive number is to set a field in wp_option like this:

add_option('unique_number', '1');

When filter is called, you must simply increment this unique number:

function genTicketString() {
    $currentUniqueNumber = get_option('unique_number');
    $newCurrentUniqueNumber = $currentUniqueNumber + 1;
    update_option('unique_number' $newCurrentUniqueNumber );

    return $newCurrentUniqueNumber;        
}

add_shortcode('quoteticket', 'genTicketString');
mariobros
  • 859
  • 4
  • 12
  • 31
  • Kindly tell me how to use this in cf7 and send the unique number to the users. I am a newbie to cf7. I have copied the function in my function.php. where to add the add_option('unique_number', '1')? –  Jan 19 '17 at 17:48
  • Is it fine to add my prefix for the number like return "17ICLAA$newCurrentUniqueNumber; ? And how to start with the three digit number? that is, 17ICLAA001 rather 17ICLAA1. –  Jan 19 '17 at 17:51
  • Mabye this will be helpful: http://stackoverflow.com/questions/6296822/how-to-format-numbers-with-00-prefixes-in-php – mariobros Jan 20 '17 at 08:14
  • it works charm. It gets increased by each time the page is refreshed. Is there any other way to create such a random number just after clicking the submit button and just before sending mail? So that I can add this number in email body and it will be in the database also. –  Jan 20 '17 at 17:14
  • @maribros by the way you have missed a comma in update_option which gave me an error message. I have noticed finally. hahah –  Jan 20 '17 at 17:16
  • Its not going with email body.. its just printing short code. –  Jan 20 '17 at 17:34
0

I have found a way to do this. Its just the number of rows+1 in the table.

When you add a record to your table the unique number also gets increased by 1 in the following code. Add the following function in function.php in your theme and use the short code "row_count" to call the function. Use it with dynamichidden text from dtx.

function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->username_wp1.SaveContactForm7_1" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );

Usually when you are creating contact forms using contact form7 it automatically creates a table in your database something like

username_wp1.SaveContactForm7_1

Instead of this replace your database table name.

So in your contact form, type

[dynamichidden uniqueid "row_count"]

and use [uniqueid] in your email body to serve your purpose.

It works fine. I have checked in my site.

David
  • 524
  • 1
  • 7
  • 24