3

I am trying to set up a registration form for a conference using PloneFormGen, and I would like to use a TALES Expression to count the number of existing records, add "1", then display this on the "Thank You" page as the registrant's registration number. Is this possible?

I have used the following to generate a random 6 digit number in the past to create a case number ID for a support request, where the number didn't matter other than to track the request, then it would be deleted once the case is closed.

python:random.randint(100000, 999999)

Am I on the right track, or am I going about this completely the wrong way?

SteveM
  • 6,058
  • 1
  • 16
  • 20
raytheengineer
  • 109
  • 2
  • 11

1 Answers1

6

I've done this in the past with the following trick:

  1. In the ZMI, I create on the form an integer property named "reg_count" containing the starting number (navigate to the form folder and append /manage_propertiesForm to the URL);

  2. Add a hidden field to the form. I used the id "regno";

  3. Use a custom script adapter to fetch the reg_count property, increment it, and put it in the request's form dictionary:

    reg_count = context.getProperty('reg_count', 0) + 1
    context.manage_changeProperties(reg_count=reg_count)
    request.form['regno'] = str(reg_count)
    
  4. Customize the thanks page to display it.

SteveM
  • 6,058
  • 1
  • 16
  • 20
  • How do I create an integer property on the form in the ZMI? If I navigate to the Form Folder in the ZMI, there is no properties tab or integer property type available to add. I am probably missing something very simple and fundamental here... – raytheengineer Mar 07 '13 at 16:32
  • Thanks, vangheem, I've integrated that into the answer. – SteveM Mar 08 '13 at 01:09
  • raytheengineer, could you let us know if this worked for you, or if you need additional help? – SteveM Mar 11 '13 at 15:34
  • This is not quite working. I was able to get the thank you page to display the reg_count value, but it did not count up. – raytheengineer Mar 11 '13 at 16:25
  • upon further investigation, it was not displaying the reg_count property, but rather just the + 1 part. No matter what value I set for reg_count, the regno is always 1. – raytheengineer Mar 11 '13 at 16:42
  • 1
    That probably means that the "reg_count" property was never created on the folder. – SteveM Mar 11 '13 at 21:07
  • When I append /manage_propertiesForm to the form, the reg_count property is there. Name: reg_count, Type: int, Value: 0. I have tried other values as well. Is there a setting that could be preventing the form from fetching and changing the property? – raytheengineer Mar 14 '13 at 13:56