Skip to content Flash-fx website
flash-fx logo image1
flash-fx logo image2
Simple solutions to complex problems. Historical swordsmanship Great online resource and forums relating to Maya and 3D.
Home << Tutorials << Plone << Creating forms and validation

Creating forms and validation

To add a customised form to your plone site you need to do the following steps:

Stage 1

  • Log into the ZMI
  • Go to portal_skins/custom, add a 'Controller Page Template' from the right hand dropdown, give it the id 'test_cpt' (without quotes) and click 'add'
  • Now we need to add an action for the form to do once it has been succesfully submitted. To do this first go to your Plone site (e.g, http://mysite) and add a new page to the root of the site called 'thank_you' (without quotes). Add a simple 'thank you' message to the page body and save it.
  • Return to the ZMI (portal_skins/custom) and select the previously created template 'test_cpt'
  • Along the top tabs click the 'actions' tab and in the section 'Add a New Form Action Override' add the following settings and then click 'Add':

    Status: success
    Content Type: Any
    Button: (leave blank)
    Action Type: redirect_to
    Action argument: string:thank_you

    This basically tells the system that when the form is successfully submitted it will redirect to a page called 'thank_you' (the one you just set up).

  • Now go to http://mysite/test_cpt and you will see a basic form with a field and a button. Press the button and the form will redirect to the thank_you page you created earlier.

Stage 2

Now we need to add a test in so that the textfield is checked for input. If it has then the form successfully submits as on stage 1. If the textfield has no text added then it errors and asks you to fill it in.

  • In the ZMI go back to the custom folder (portal_skins/custom) and from the right hand dropdown add a 'Controller Validator'. Give it the id 'test_cv' and click 'Add'. This will give you a default controller validator template and is already configured to check the textfield on your test_cpt page.
  • Select 'test_cpt' and click the 'Validation' tab along the top.
  • In the 'Add New Form/Script Validator Override' section add the following settings and click 'Add':

    Template: test_cpt
    Content type: Any
    Button: (leave blank)
    Validators: test_cv

    This is basically telling the current script (test_cpt) to use the validation script called 'test_cp' (the one you just created) to validate with.

    Now go back to your page (http://mysite/test_cpt) and press the Submit button without adding any text to the textfield. You will see an error in bold text appear above the textfield. To submit the form successfully you will need to add text to the field and then press Submit.