We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37229
    • 3 Posts
    Hello,
    formit2db works very well. In our former scripts we inserted new data like this:
      $SQL_insert="INSERT INTO tablename... 
           $bool=mysql_query($SQL_insert);
           $id = mysql_insert_id();

    How can I get the current ID of the new row using the formit2db-code? Is
    $modx->lastInsertId(); 
    the right way?

    Thank you, Peter
      • 4172
      • 5,888 Posts
      you can try:

      $dataobject->save();
      $id = $dataobject->get('id');
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37229
        • 3 Posts
        Thanks a lot Bruno, this works great!
          • 37229
          • 3 Posts
          Still another question: am I right that in order to avoid cross site scripting, values in form-fields should be written like this?

          value="[[!+fi.placeholdername:htmlent]]"


          Before we used formIt and formit2db our form-data were sanitized by the following code:

          $email = htmlspecialchars($_POST['email'],ENT_QUOTES);


          I wanted to do this in our formIt-and-formit2db-based forms and added the following line (5) in the formit2db-snippet:

          $allFormFields = $hook->getValues();   
          foreach ($allFormFields as $field=>$value){
               
              if ($field !== 'spam' && $field !== 'resource_id'){
                  ADDED LINE: $value=htmlspecialchars($value,ENT_QUOTES);
                  $dataobject->set($field,$value);
              }      
          }


          It seems to work well, but as I am not very experienced in OOP and ModX I would like to ask the experts among you, if this is a good solution? Or would you suggest other strategies to prevent cross site scripting?

          Thank you, Peter

            • 34178
            • 212 Posts
            Hi Bruno,

            we want to install a threestage registration including 3 forms on three sites:

            First Form on the first site: asking for firstname and lastname
            Second Form on the second site: asking for email-adress
            Third Form on the third site: asking for hobbies and so on

            the second and third form are supposed to update the tablerow which is generated after sending form 1

            Do you have any idea how to realize this by db2formit and formit2db? We already added

            &preHooks=`db2formit`
            &resId=`24`


            to the snippet call where 24 is the row we wanted to update by formit2db but instead of updating row 24 there has been generated a new table row.

            Do you have any idea how to realize this?

            Letti


              • 36704
              • 131 Posts
              Hi bruno,

              Im sorry for my ignorance here...
              Can you teach me step by step on how to use your snippets please?
              Do i need to create another database on my phpMyadmin or this snippets will autocreate?

              Thanks you in advance,
              Larry Sabino
                • 37213
                • 25 Posts
                Hi All,

                Is there in formit2db a setting for exists validation (example the email field inside my database) if not, who can push me to the right direction thanks...
                  • 4172
                  • 5,888 Posts
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 42681
                    • 64 Posts
                    As far as I can see formit2db is an official snippet now:

                    http://modx.com/extras/package/formit2db

                    But what about security?

                    Normally when using mysql-queries one of the most important things is to use "mysql_real_escape_string" to be sure the mysql-query cannot be modified by hackers.

                    How does this work in modx and especially in formit2db ord db2formit? Is this kind of cleaning automatically done by xpdo or are there any security-concerns?
                      • 37747
                      • 50 Posts
                      Hi Bruno,

                      First of all thanks for your scripts, I am using some formit2resource on the site for users to submit reviews and it's working great.

                      I tried using the formit2db script but I get:
                      addPackage called with an invalid package name

                      in the modx error.log

                      What I am trying to do is store the contact information in the database. These are the steps I have taken:

                      Table name:
                      modx_dragon_contact

                      [[FormIt]] call contains this:
                      &hooks=`spam,formit2db,email`
                      &preHooks=`db2formit`
                      &prefix=`modx_dragon_`
                      &packageName=`dragonContact`
                      &tablename=`contact`
                      


                      The table has fields such as: firstname, lastname, email etc. which are also included in the form:
                      eg.
                      <input type="text" tabindex="1" name="firstname">


                      ...but anyway, I don't even get as far as form submission, the "invalid package name" error is triggered on page load and no folders are created inside /core/components/

                      I have checked the write permission of the folder, that is fine.

                      Versions
                      - Modx: 2.2.6
                      - Formit: 2.2.0
                      - FormIt2db: 1.0.1

                      Site is running on MAMP with PHP version 5.4.4