We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21767
    • 44 Posts
    After all that it is hard to me to bring Register to success. It was only one time possible here to create a new user in the database. It was the same with the installation before. Don’t no why.
      • 21767
      • 44 Posts
      Please, I need help.

      Again, I try to use Register in Rev. 2.0.0. pl

      I am using this call:

      [[Register?
      &submitVar=`registerbtn`
      &activationResourceId=`14`
      &activationEmailSubject=`Thanks for Registering!`
      &submittedResourceId=`19`
      &activation=`0`
      ]]

      The rest is the same than in the common Register-Example.

      This worked only one time with the message `Thanks for Registering!`. After that, it was no longer possible to add more users in the database table "..._users". No error message. No call of submittedResourceId.

      What’s wrong?
      How to debug?
        • 28215
        • 4,149 Posts
        Call it uncached: [[!Register]]
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 21767
          • 44 Posts
          yes, it helps. thanks.

          You should change the online doc.

          It’s terrible for newbies.
            • 21767
            • 44 Posts
            Now I have successfully applied UpdateProfile. I am also able to add other fields to the form, for example:
              
              <tr><td><label for="comment">[[!%login.comment]] <span class="error">[[+error.comment]]</span></label></td>
                  <td><input type="text" name="comment" id="comment" value="[[+comment]]" /></td></tr>
              <tr><td><label for="role">[[!%login.role]] <span class="error">[[+error.role]]</span></label></td>
                  <td><input type="text" name="role" id="role" value="[[+role]]" /></td></tr>
            



            It works, too.

            My next idea was to use a select/option field for role like this:

              <tr><td><label for="role">[[!%login.role]] <span class="error">[[+error.role]]</span></label></td>
                  <td><select name="role" id="role" value="[[+role]]" />
                      <option value ="1">User</option>
                      <option value ="2">Reviewer</option></td></tr>
            


            But it doesn’t work with the placeholders.
            How to solve the problem?
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You can’t give a select tag a content attribute, the individual option elements have to be set as selected or not.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 14883 ☆ A M B ☆
                • 450 Posts
                One solution: put your options in an array rather than hard coding the html... then iterate through the array comparing the values with the placeholder, and add a ’selected="selected"’ attribute to the html if they match. Kinda like this:

                <select name="role" id="role" />
                          [[!roleOptions? &selected=`[[+role]]`]]
                </select>


                roleOptions is a snippet that reads a PHP array and outputs <option> tags:
                <?php
                  $opts = array(1=>'User',2=>'Reviewer'); // values for the <option> array
                  $return = ''; // the return chunk
                  foreach ($opts as $key=>$val) {
                      // add 'selected' attribute if the array key matches the placeholder
                      $sel = (isset($selected) && $key == $selected) ? 'selected="selected"' : ''; 
                      $return .= "<option $sel value=\"$key\">$v</option>\n";  // append html to output string
                  }
                  return $return;
                ?>
                


                That should work. You can make it more usable by creating a single snippet that gets the options array from an argument (rather than needing a separate snippet for each set of options). [[!opts? &array=`role` &selected=`[[+role]]`]]. I keep my arrays in external include files (you could also generate them from a database table of all possible values).

                I’ve been thinking of writing a tutorial on this. Not sure how other people are handling this sort of thing in MODx; maybe there are more elegant solutions.
                  • 21767
                  • 44 Posts
                  This works and collaborates with the database:

                  <?php
                  $opts = array(0 => 'nothing',
                                1 => 'User',
                                2 => 'Reviewer', 
                                3 => 'Author'  ); // values for the <option> array  
                  
                    foreach ($opts as $key=>$val) {
                        // add 'selected' attribute if the array key matches the placeholder
                        $sel = (isset($selected) && $key == $selected) ? 'selected="selected"' : ''; 
                        echo "<option $sel value=\"$key\">$val </option>\n";  // append html to output string
                    }
                    return '';
                  ?>
                    • 21767
                    • 44 Posts
                    Quote from: jrotering at Jul 28, 2010, 12:06 PM


                    I’ve been thinking of writing a tutorial on this. Not sure how other people are handling this sort of thing in MODx; maybe there are more elegant solutions.

                    It would be the optimum to use an fully customizable modx-object. The problem is that it would be a Sisyphean undertaking to implement all such cases. But it helps me to see other real examples of solutions.