Jump to:

11002 Posts in 2734 Topics by 1823 members

All other Modules

SilverStripe Forums » All other Modules » Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2320 Views
  • Kalileo
    Avatar
    Community Member
    127 Posts

    Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    There is a bug in the current UserForm 0.2 code which affects translated forms in SS 2.3.2, and which has the effect that form fields and email addresses cannot be added to the translated forms.

    The following is explaining in more detail how to workaround the bug in UserForms 0.2, as Juanitou and kateh are discussing it there and on the following pages.

    I'm assuming that you have already created a complete form, defined the fields and added the e-mail addresses to send it to. Further I assume you have already created the basic translated from, however you could not add any fields to it, nor could you add the e-mail addresses to which to send the submitted forms.

    The quickest and in my eyes easiest way to add the fields for the translated forms is to access your silver stripe database in PHPMyAdmin.

    On the left side you see the table names listed. Click on table UserDefinedForm. and then on the top on Browse. Here you see the forms you have created so far. There should be (at least) one record for the original form and one record for the translated form. Look at the field ID for both records and note them.

    To create the fields click on the table EditableFormField. on the left side. In the frame on the right side you will see the structure of this table. Click on Browse and you will see the fields you have created so far. You see their names in the field name. Have a look at the field ParentID, the number you see there refers to the forms to which they belong.

    Now click on Export, and without changing the defaults click on Go. Among other things it will show you an insert statement similar to the one below:

    INSERT INTO `EditableFormField` (`ID`, `ClassName`, `Created`, `LastEdited`, `Name`, `Title`, `Default`, `Sort`, `Required`, `CanDelete`, `CustomErrorMessage`, `CustomRules`, `CustomSettings`, `ParentID`) VALUES
    (1, 'EditableTextField', '2009-07-24 22:53:50', '2009-07-25 22:06:38', 'EditableTextField1', 'Your Name', NULL, 1, 1, 1, NULL, 'a:0:{}', 'a:5:{s:4:"Size";s:2:"32";s:9:"MinLength";s:1:"0";s:9:"MaxLength";s:2:"50";s:4:"Rows";s:1:"1";s:10:"ShowOnLoad";s:4:"Show";}', 2),
    (2, 'EditableEmailField', '2009-07-24 22:55:08', '2009-07-25 22:06:38', 'EditableEmailField2', 'Your E-mail Address', NULL, 2, 1, 1, NULL, 'a:0:{}', 'a:1:{s:10:"ShowOnLoad";s:4:"Show";}', 2),
    (3, 'EditableTextField', '2009-07-24 22:55:41', '2009-07-25 22:06:38', 'EditableTextField3', 'Your Message', NULL, 3, 1, 1, NULL, 'a:0:{}', 'a:5:{s:4:"Size";s:2:"32";s:9:"MinLength";s:1:"0";s:9:"MaxLength";s:4:"1000";s:4:"Rows";s:1:"6";s:10:"ShowOnLoad";s:4:"Show";}', 2);

    Copy that your text editor, and now change:

    • if the field ID (the first one) contained 1, 2, and 3, as in this example, change it to 4, 5, and 6, or accordingly.
    • translate the field Name, this is the label which will be shown for the field.
    • in the field ParentID (the last one) change the number (in my example 2) to the ID of the translated form (in my example 5), which you noted earlier.

    As an example, now it could look like this:

    INSERT INTO `EditableFormField` (`ID`, `ClassName`, `Created`, `LastEdited`, `Name`, `Title`, `Default`, `Sort`, `Required`, `CanDelete`, `CustomErrorMessage`, `CustomRules`, `CustomSettings`, `ParentID`) VALUES
    (4, 'EditableTextField', '2009-07-24 22:53:50', '2009-07-25 22:06:38', 'EditableTextField1', 'Ihr Name', NULL, 1, 1, 1, NULL, 'a:0:{}', 'a:5:{s:4:"Size";s:2:"32";s:9:"MinLength";s:1:"0";s:9:"MaxLength";s:2:"50";s:4:"Rows";s:1:"1";s:10:"ShowOnLoad";s:4:"Show";}', 8),
    (5, 'EditableEmailField', '2009-07-24 22:55:08', '2009-07-25 22:06:38', 'EditableEmailField2', 'Ihre E-mail Adresse', NULL, 2, 1, 1, NULL, 'a:0:{}', 'a:1:{s:10:"ShowOnLoad";s:4:"Show";}', 8),
    (6, 'EditableTextField', '2009-07-24 22:55:41', '2009-07-25 22:06:38', 'EditableTextField3', 'Ihre Nachricht', NULL, 3, 1, 1, NULL, 'a:0:{}', 'a:5:{s:4:"Size";s:2:"32";s:9:"MinLength";s:1:"0";s:9:"MaxLength";s:4:"1000";s:4:"Rows";s:1:"6";s:10:"ShowOnLoad";s:4:"Show";}', 8);

    Click on SQL on top, a text field will be shown. Replace whatever is shown there ("SELECT ...") with the insert statement which you just edited.

    Click on Go.

    Assuming there are no typos and no error messages the fields will now show up in the translated form

    To add the e-mail address to send the form to we need to do the same in the table UserDefinedForm_EmailRecipient.

    Again here an example of the insert statement which you get when you export that table:

    INSERT INTO `UserDefinedForm_EmailRecipient` (`ID`, `ClassName`, `Created`, `LastEdited`, `EmailAddress`, `EmailSubject`, `EmailFrom`, `EmailBody`, `SendPlain`, `FormID`, `SendEmailFromFieldID`, `SendEmailToFieldID`) VALUES
    (1, 'UserDefinedForm_EmailRecipient', '2009-07-24 10:30:50', '2009-07-24 10:30:50', 'info@yourdomain.com', 'Contact Form of yourdomain.com', 'noreply@yourdomain.com', NULL, 0, 2, 0, 0);

    Assuming you want the same e-mail address as recipient for both forms, all you need to do is to change the field FormID (the third to last field), as done here:

    INSERT INTO `UserDefinedForm_EmailRecipient` (`ID`, `ClassName`, `Created`, `LastEdited`, `EmailAddress`, `EmailSubject`, `EmailFrom`, `EmailBody`, `SendPlain`, `FormID`, `SendEmailFromFieldID`, `SendEmailToFieldID`) VALUES
    (1, 'UserDefinedForm_EmailRecipient', '2009-07-24 10:30:50', '2009-07-24 10:30:50', 'info@yourdomain.com', 'Contact Form of yourdomain.com', 'noreply@yourdomain.com', NULL, 0, 8, 0, 0);

    Then click again on SQL on top and do as before.

    That's it, I hope it helps until UserForms 0.2 is fixed.

  • dab
    Avatar
    Community Member
    50 Posts
  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    Dear Kalileo, thanks for the effort, I should have done it myself. I hope that the new version of the module will be published soon.

    Best regards,
    Juan

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    You're welcome, dab and Juan

    BTW, the javascript form validation does not work in the KDE browser, Konqueror. It works in Firefox though. If you look at the page source code, the javascript validation code seems to be added twice at the end of the page :o

  • ragunalth
    Avatar
    Community Member
    14 Posts

    Re: Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    Could someone please tell me if they have written a script to do this?

    If someone have some script to copy the form from the English to any other language it would be great.

    Please share.

  • ragunalth
    Avatar
    Community Member
    14 Posts

    Re: Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    Here is a hack to copy a form from the original language.

    In the templates/FieldEditor.css

    <% if Fields %>
    <% else %>
    <div class="">
    <h3>Importing from original form</h3>
    <input rel="$theparentid" class="importingOriginalForm" type="button" value="Import now">
    </div>
    <% end_if %>

    In the userforms/javascript/UserForm.js

    /**
    * Importing form data
    *
    */
    $(".importingOriginalForm").livequery('click', function() {
    statusMessage("Importing from original form");

    var parent = $(this).attr("rel");
    var action = 'admin/duplicatethisform/'+parent;
    $.ajax({
    type: "GET",
    url: action,
    data: "parentID=0&ajax=1",
    // create a new field
    success: function(msg){
    statusMessage("Importing form successfull");
    window.location.reload();
    },

    // error creating new field
    error: function(request, text, error) {
    statusMessage("Importing form failed");
    }
    });
    return false;

    });

    function duplicatethisform() {
    if(($id = $this->urlParams['ID']) && is_numeric($id)) {
    $page = DataObject::get_by_id("SiteTree", $id);
    if($page && !$page->canEdit()) return Security::permissionFailure($this);

    $newPage = $page->getTranslation(Translatable::default_locale());
    foreach($newPage->Fields() as $field) {
    $newField = $field->duplicate();
    $newField->ParentID = $page->ID;
    $newField->write();
    }
    foreach($newPage->EmailRecipients() as $recipient) {
    $newER = $recipient->duplicate();
    $newER->FormID = $page->ID;
    $newER->write();
    }
    return $this->returnItemToUser($page);
    } else {
    user_error("CMSMain::duplicatethisform() Bad ID: '$id'", E_USER_WARNING);
    }

    }

  • Doverose
    Avatar
    Community Member
    8 Posts

    Re: Workaround for bug in UserForm 0.2 which affects the creation of fields in translated forms in SS 2.3.2 Link to this post

    Hi
    I picked up your useful concept here but I get this error (using SS 2.3.6):

    syntax error
    [Break on this error] if($id = $this->urlParams['ID'] && is_numeric($id)){\n

    Can you hep?

    2320 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.