We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16430
    • 217 Posts
    I cannot make resource2formit populate multiple select fields.
    It only works when there is only one value in that TV. If there is value1||value2 then it insert nothing in the multiple select field. [ed. note: kudykam last edited this post 11 years, 1 month ago.]
      • 43374
      • 39 Posts
      How would look the syntax to select the parent via predefined dropdown?

      for parent:
          <label for="parent">
              Parent:
              <span class="error">[[+fi.error.parent]]</span>
          </label>
          <input id="parent" name="parent:required" type="text" value="[[+fi.parent]]" />  
          <br/>


      for dropdown in a TV:
      <select name="color">
         <option value="blue" [[!+fi.color:FormItIsSelected=`blue`]] >Blue</option>
         <option value="red" [[!+fi.color:FormItIsSelected=`red`]] >Red</option>
         <option value="green" [[!+fi.color:FormItIsSelected=`green`]] >Green</option>
       
         <!-- This would also work -->
         <option value="yellow" [[!+fi.color:is=`yellow`:then=`selected`]]>Yellow</option>
      </select>
        • 40024
        • 72 Posts
        I think that i may have found a bug in @xxxmicrobexxx nice modification of @Bruno's snippet. The post can be found here:

        http://forums.modx.com/thread/?thread=31314&page=6

        The problem:
        If a user creates 2 resources with the same name, then the same alias is set for both resources, thus resulting in this error created in the error log:
        Resource URI testContainer/test-resource already exists for resource id = 29; skipping duplicate resource URI for resource id = 30

        And then of course if anyone tries to view the page created he/she can't. I wonder if this could be fixed.

        This is an awesome snippet by the way laugh

          • 16430
          • 217 Posts
          I solved this by putting resource id infront of alias:
          // now set the alias
          $doc->set('alias', $alias);
          $doc->set('template', '1'); //template id
          $doc->save();
          
          // have to repeat because ID is created after resource save
          //set, title and ID into alias
          $alias = $doc->get('id') . '-' . $alias;
          $doc->set('alias', $alias);
          $doc->save();
          
            • 40024
            • 72 Posts
            Excellent work mate! It works perfectly laugh

            EDIT: After carefully examining @kudykam's code,i noticed that now all newly created resources are like this: "id-alias" .
            So, using his code and some other code i found in a thread(don't remember where,sorry), i made a small update:

            //Check is alias already exists,and if it does it appends a number //in the end(eg already existing alias Maria becomes Maria2)
            if($modx->getCount(modResource, array('alias'=>$alias))!= 0) {
            $count = 2;
            $newAlias = $alias;
            while($modx->getCount(modResource, array('alias'=>$newAlias))!= 0) {
            $newAlias = $alias;
            $newAlias .= '-' . $count;
            $count++;
            }
            $alias = $newAlias;
            }


            Just place it above the:
            // now set the alias
            $doc->set('alias', $alias);
            $doc->set('template', '1');
            $doc->save();


            If you want the duplicated resources to start from 1, then change
            $count = 2;
            to
            $count = 1;
            (e.g. already existing alias Maria becomes Maria1, and so on)
            [ed. note: dinpapa last edited this post 11 years ago.]
              • 12410
              • 353 Posts
              Hi Guys,
              Anyway to upload a file e.g. pdf,doc to a TV from the frontend e.g. say a public user wanted to submit a resume and link it to his profile (ie a Resource). I think Bruno mentioned that he was able to do it?
              Thanks
                • 41101
                • 40 Posts
                How would I go about adapting Bruno's code to create a new post in the Articles add on?

                Is it simply adapting the code so that the object is Articles or is there a lot more to it?

                Thanks.
                • Hi guys,

                  I'm trying to edit a document created with formit2resource

                  I have a link <p><a href="[[~646? &resId=`876`]]">Edit resource</a></p>

                  and it goes the right resource when I click it.

                  then what actually outputs on the page is

                  Array
                  (
                  [id] => 876
                  [type] => document
                  [contentType] => text/html
                  [pagetitle] => TEST CREATE 3
                  [longtitle] =>
                  [description] =>
                  [alias] => task1386076021
                  [link_attributes] =>
                  [published] => 1
                  [pub_date] => 0
                  [unpub_date] => 0
                  [parent] => 164
                  [isfolder] =>
                  [introtext] =>
                  [content] =>
                  [richtext] => 1
                  [template] => 7
                  [menuindex] => 0
                  [searchable] => 1
                  [cacheable] => 1
                  [createdby] => 254
                  [createdon] => 2013-12-03 17:07:01
                  [editedby] => 0
                  [editedon] => 0
                  [deleted] =>
                  [deletedon] => 0
                  [deletedby] => 0
                  [publishedon] => 0
                  [publishedby] => 0
                  [menutitle] =>
                  [donthit] =>
                  [privateweb] =>
                  [privatemgr] =>
                  [content_dispo] => 0
                  [hidemenu] =>
                  [class_key] => modDocument
                  [context_key] => web
                  [content_type] => 1
                  [uri] => task1386076021.html
                  [uri_override] => 0
                  [hide_children_in_tree] => 0
                  [show_in_tree] => 1
                  [properties] =>
                  )

                  with the form underneath it and none of the fields are populated.

                  the formit call(s) on that page are:

                  [[!FormIt? &hooks=`spam,formit2step,email` &preHooks=`resource2formit` &resource2formitfields=`parent,longtitle,content`&emailTpl=`myEmailChunk` $submitvar=`editForm` &emailTo=`[email protected]`]]

                  <p>[[+fi.error.error_message]]</p>
                  <form class="form" action="[[+fi.id]]" id="myEditForm" name="myEditForm" method="post">
                  <input type="hidden" name="nospam:blank" />
                  <input type="hidden" name="resource_id" value="[[+fi.id]]" />
                  <input type="text" name="taskParent" value="[[+fi.taskParent]]" />


                  <label for="pagetitle">Edit Quick Task Title: <span class="error">[[+fi.error.pagetitle]]</span> </label>

                  <input id="pagetitle" type="text" name="pagetitle" value="[[+fi.pagetitle]]" size="50"/>

                  <label for="keywords">
                  Edit Keywords:
                  <span class="error">[[+fi.error.keywords]]</span>
                  </label>



                  <textarea id="keywords" name="keywords" rows="7" cols="55">[[+fi.keywords]]</textarea> <br class="clear" />


                  <div class="form-buttons"><input type="submit" value="Edit Resource" name="editForm" onsubmit="return false;"/></div>
                  </form>


                  Any thoughts?
                    ________

                    Anne
                    Toad-in-Chief
                    Red Toad Media - Web Design, Louisville KY
                    Hear me tweet: http://www.twitter.com/redtoadmedia
                    "Bring on the imperialistic condiments." - Rory Gilmore
                  • never mind, I commented these two lines:

                    // $errorMsg = '<pre>'.print_r($docarray,true).'</pre>';
                    // $hook->addError('error_message',$errorMsg);

                    and also rechecked my &resource2formitfields and fixed those and now its ok. I know this is loading parameters via get request but I load this with AJAX now into tabs...going to go experiment but if anyone has ideas? that would be awesome.

                      ________

                      Anne
                      Toad-in-Chief
                      Red Toad Media - Web Design, Louisville KY
                      Hear me tweet: http://www.twitter.com/redtoadmedia
                      "Bring on the imperialistic condiments." - Rory Gilmore
                    • $submitvar
                      smiley