We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51020
    • 670 Posts
    Hi there

    I have a user Extended field called 'company' which collects the company name when a user Registers using the Login.Register snippet.

    When a user registers, this information is successfully added as a an extended field.

    But - when i try and use this (I have a simple quote form, which pulls in their details if they are logged in) - all the other standard fields are pulled in, but the Company is not.

    This is what I have in my form:
    <form action="[[~236]]" method="post">
    
            <label for="name">Name</label>
            <input type="text" name="name" id="name" required value="[[+name]]" />
    
            <label for="company">Company</label>
            <input type="text" name="company" id="company" required value="[[+company]]" />
    
            <label for="address">Address</label>
            <input type="text" name="address" id="address" required value="[[+address]]" />
      
            <label for="city">City</label>
            <input type="text" name="city" id="city" required value="[[+city]]" />
    
            <label for="postcode">Post code</label>
            <input type="text" name="postcode" id="postcode" maxlength="10" required value="[[+postcode]]" />
      
        <button class="btn" type="submit" name="submit" />Get Quote</button>
    
    </form>
    


    Do I need to add something different to a standard placeholder in order to pull in the company field?

    Thanks in advance.
    Andy

    This question has been answered by lkfranklin. See the first response.

      • 17301
      • 932 Posts
      What are you using to pull in the users fields? profile, personalise or a custom snippet?
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 51020
        • 670 Posts
        Quote from: lkfranklin at May 10, 2018, 03:57 AM
        What are you using to pull in the users fields? profile, personalise or a custom snippet?

        Sorry for the lack of info! It's a custom snippet.
        This is what I have to call in the variables:

        // Get posted variables
        $name = $profile->fullname;
        $company = $profile->company;
        $address = $profile->address;
        $city = $profile->city;
        $postcode = $profile->zip;
        $country = $profile->country;
        $email = $profile->email;
        $phone = $profile->phone;
        
        


        Wasn't sure if I needed something different for 'company' as it's not a standard field?

        Thanks
        Andy
          • 17301
          • 932 Posts
          Yeah the extended fields are stored as json elsewhere.

          $profile = $modx->user->getOne('Profile');
          $extended = $profile->get('extended');
          echo $extended['company'];
          

          [ed. note: lkfranklin last edited this post 8 years, 4 months ago.]
            ■ email: [email protected] | ■ website: https://alienbuild.uk

            The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
            • 51020
            • 670 Posts
            Quote from: lkfranklin at May 10, 2018, 04:25 AM
            Yeah the extended fields are stored as json elsewhere.

            <!--?php
            $extended = $profile--->get('extended');
            echo $extended['company'];


            Wow thanks for this. I'm not quite sure what to do with it though.
            I pasted it into my snippet, but it doesn't run at all now.

            Thanks again
            Andy
            • discuss.answer
              • 17301
              • 932 Posts
              Sorry forgot to define $profile at the top of my code.

              $profile = $modx->user->getOne('Profile');
              $extended = $profile->get('extended');
              echo $extended['company'];
              
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                • 51020
                • 670 Posts
                Quote from: lkfranklin at May 10, 2018, 04:51 AM
                Sorry forgot to define $profile at the top of my code.

                $profile = $modx->user->getOne('Profile');
                $extended = $profile->get('extended');
                echo $extended['company'];
                

                I forgive you! lol. smiley
                I still cannot get it working though - below is the complete snippet I have:

                
                <?php
                session_start();
                
                $output = '';
                $items = '';
                $basket_total = 0;
                
                $errors = array();
                $success = array();
                
                
                
                //---------------------------------------------------------------
                // Get user profile if they are logged in
                $user = $modx->getUser();
                $profile = $user->getOne('Profile');
                
                
                
                //-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
                $profile = $modx->user->getOne('Profile');
                $extended = $profile->get('extended');
                echo $extended['company'];
                //-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
                
                
                
                
                // Get posted variables
                $name = $profile->fullname;
                //$company = $profile->company;
                $address = $profile->address;
                $city = $profile->city;
                $postcode = $profile->zip;
                $country = $profile->country;
                $email = $profile->email;
                $phone = $profile->phone;
                
                
                
                //---------------------------------------------------------------
                
                $basket = $_SESSION['basket'];
                foreach ($basket as $key => $item) {
                    $items .= $modx->getChunk('duraflex.quote.row', $item);
                    $basket_total += $item['quantity'] * $item['price'];
                }
                
                //---------------------------------------------------------------
                
                if (isset($_POST['submit'])) {
                
                    // Get posted variables
                    $name = $_POST['name'];
                    $company = $_POST['company'];
                    $address = $_POST['address'];
                    $city = $_POST['city'];
                    $postcode = $_POST['postcode'];
                    $country = $_POST['country'];
                    $email = $_POST['email'];
                    $phone = $_POST['phone'];
                
                    // Get MODX settings
                    $to = '[email protected]'; //$modx->getOption('emailsender');
                    $from = $modx->getOption('emailsender');
                    $site_name = $modx->getOption('site_name');
                    $subject = "Duraflex: Quote request by $name";
                    $message = $modx->getChunk('duraflex.quote.email', array(
                        'items' => $items,
                        'name' => $name,
                        'company' => $company,
                        'address' => $address,
                        'city' => $city,
                        'postcode' => $postcode,
                        'country' => $country,
                        'email' => $email,
                        'phone' => $phone,
                
                    ));
                
                    // Send email: TODO
                    $modx->getService('mail', 'mail.modPHPMailer');
                    $modx->mail->reset();
                    $modx->mail->set(modMail::MAIL_BODY, $message);
                    $modx->mail->set(modMail::MAIL_FROM, $from);
                    $modx->mail->set(modMail::MAIL_FROM_NAME, $site_name);
                    $modx->mail->set(modMail::MAIL_SENDER, $from);
                    $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                    $modx->mail->address('to', $to);
                    $modx->mail->address('to', '[email protected]');
                    $modx->mail->setHTML(true);
                
                    if (!$modx->mail->send()) {
                        $modx->log(modX::LOG_LEVEL_ERROR,'[FormIt] An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
                        return false;
                    }
                    $modx->mail->reset();
                
                    $output = $modx->getChunk('duraflex.quote.confirmation', array(
                        'title' => $title,
                        'errors' => implode('</li><li>', $errors),
                        'success' => implode('</li><li>', $success),
                        'items' => $items,
                        'name' => $name,
                        'company' => $company,
                        'address' => $address,
                        'city' => $city,
                        'postcode' => $postcode,
                        'country' => $country,
                        'email' => $email,
                        'phone' => $phone,
                    ));
                
                    // Save to user account if applicable
                    if ($user = $modx->getUser()) {
                        
                        // Save their order to the database
                        if ($modx->addPackage('duraflex', MODX_CORE_PATH . 'components/duraflex/model/', 'me')) {
                            $order = $modx->newObject('Duraflex');
                            $order->set('userid', $user->get('id'));
                            $order->set('status', 'new');
                            $order->set('orderdate', date("Y-m-d H:i:s"));
                            $order->set('data', json_encode($basket));
                            $order->save();
                        }
                        
                        // Update user profile with the details they entered?
                        // if ($profile = $modx->getObject('modUserProfile', array('internalKey' => $id))) {
                            // $fullname = $profile->get('fullname');
                        // }
                  
                        
                        
                    }
                
                    // Destroy basket
                    unset($_SESSION['basket']);
                
                
                } else {
                
                    $output = $modx->getChunk('duraflex.quote', array(
                        'title' => $title,
                        'errors' => implode('</li><li>', $errors),
                        'success' => implode('</li><li>', $success),
                        'items' => $items,
                        'name' => $name,
                        'company' => $company,
                        'address' => $address,
                        'city' => $city,
                        'postcode' => $postcode,
                        'country' => $country,
                        'email' => $email,
                        'phone' => $phone,
                        'basket_total' => $basket_total,
                    ));
                
                }
                
                return $output;
                
                


                Sorry - I'm just not sure if I'm putting it in the right place?
                  • 51020
                  • 670 Posts
                  UPDATE: I can actually see that it's printing the company name at the top of my quote page - so it IS working - but I need to put the echo statement elsewhere. It's using POST to populate the fields - I'm not sure how to get it into the actual field itself?

                  Almost there!!

                  Andy
                    • 51020
                    • 670 Posts
                    GOT IT: With a bit io trial and error - I worked it out - see below if interested:
                    
                    // Get posted variables
                    $name = $profile->fullname;
                    $company = $extended['company'];
                    $address = $profile->address;
                    $city = $profile->city;
                    $postcode = $profile->zip;
                    $country = $profile->country;
                    $email = $profile->email;
                    $phone = $profile->phone;
                    


                    Thanks so much for the help LK!

                    Andy
                      • 17301
                      • 932 Posts
                      Try this:

                      <?php
                      session_start();
                       
                      $output = '';
                      $items = '';
                      $basket_total = 0;
                       
                      $errors = array();
                      $success = array();
                       
                       
                       
                      //---------------------------------------------------------------
                      // Get user profile if they are logged in
                      $user = $modx->getUser();
                      $profile = $user->getOne('Profile');
                       
                       
                       
                      //-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
                      /*$profile = $modx->user->getOne('Profile');*/
                      $extended = $profile->get('extended');
                      echo $extended['company'];
                      //-- ADDITIONAL CODE ADDED 10.05.18 - NOT WORKING
                       
                       
                       
                       
                      // Get posted variables
                      $name = $profile->fullname;
                      $company = $extended['company'];
                      //$company = $profile->company;
                      $address = $profile->address;
                      $city = $profile->city;
                      $postcode = $profile->zip;
                      $country = $profile->country;
                      $email = $profile->email;
                      $phone = $profile->phone;
                       
                       
                       
                      //---------------------------------------------------------------
                       
                      $basket = $_SESSION['basket'];
                      foreach ($basket as $key => $item) {
                          $items .= $modx->getChunk('duraflex.quote.row', $item);
                          $basket_total += $item['quantity'] * $item['price'];
                      }
                       
                      //---------------------------------------------------------------
                       
                      if (isset($_POST['submit'])) {
                       
                          // Get posted variables
                          $name = $_POST['name'];
                          /*$company = $_POST['company'];*/
                          $company = $extended['company'];
                          $address = $_POST['address'];
                          $city = $_POST['city'];
                          $postcode = $_POST['postcode'];
                          $country = $_POST['country'];
                          $email = $_POST['email'];
                          $phone = $_POST['phone'];
                       
                          // Get MODX settings
                          $to = '[email protected]'; //$modx->getOption('emailsender');
                          $from = $modx->getOption('emailsender');
                          $site_name = $modx->getOption('site_name');
                          $subject = "Duraflex: Quote request by $name";
                          $message = $modx->getChunk('duraflex.quote.email', array(
                              'items' => $items,
                              'name' => $name,
                              'company' => $company,
                              'address' => $address,
                              'city' => $city,
                              'postcode' => $postcode,
                              'country' => $country,
                              'email' => $email,
                              'phone' => $phone,
                       
                          ));
                       
                          // Send email: TODO
                          $modx->getService('mail', 'mail.modPHPMailer');
                          $modx->mail->reset();
                          $modx->mail->set(modMail::MAIL_BODY, $message);
                          $modx->mail->set(modMail::MAIL_FROM, $from);
                          $modx->mail->set(modMail::MAIL_FROM_NAME, $site_name);
                          $modx->mail->set(modMail::MAIL_SENDER, $from);
                          $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                          $modx->mail->address('to', $to);
                          $modx->mail->address('to', '[email protected]');
                          $modx->mail->setHTML(true);
                       
                          if (!$modx->mail->send()) {
                              $modx->log(modX::LOG_LEVEL_ERROR,'[FormIt] An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
                              return false;
                          }
                          $modx->mail->reset();
                       
                          $output = $modx->getChunk('duraflex.quote.confirmation', array(
                              'title' => $title,
                              'errors' => implode('</li><li>', $errors),
                              'success' => implode('</li><li>', $success),
                              'items' => $items,
                              'name' => $name,
                              'company' => $company,
                              'address' => $address,
                              'city' => $city,
                              'postcode' => $postcode,
                              'country' => $country,
                              'email' => $email,
                              'phone' => $phone,
                          ));
                       
                          // Save to user account if applicable
                          if ($user = $modx->getUser()) {
                               
                              // Save their order to the database
                              if ($modx->addPackage('duraflex', MODX_CORE_PATH . 'components/duraflex/model/', 'me')) {
                                  $order = $modx->newObject('Duraflex');
                                  $order->set('userid', $user->get('id'));
                                  $order->set('status', 'new');
                                  $order->set('orderdate', date("Y-m-d H:i:s"));
                                  $order->set('data', json_encode($basket));
                                  $order->save();
                              }
                               
                              // Update user profile with the details they entered?
                              // if ($profile = $modx->getObject('modUserProfile', array('internalKey' => $id))) {
                                  // $fullname = $profile->get('fullname');
                              // }
                         
                               
                               
                          }
                       
                          // Destroy basket
                          unset($_SESSION['basket']);
                       
                       
                      } else {
                       
                          $output = $modx->getChunk('duraflex.quote', array(
                              'title' => $title,
                              'errors' => implode('</li><li>', $errors),
                              'success' => implode('</li><li>', $success),
                              'items' => $items,
                              'name' => $name,
                              'company' => $company,
                              'address' => $address,
                              'city' => $city,
                              'postcode' => $postcode,
                              'country' => $country,
                              'email' => $email,
                              'phone' => $phone,
                              'basket_total' => $basket_total,
                          ));
                       
                      }
                       
                      return $output;
                      
                        ■ email: [email protected] | ■ website: https://alienbuild.uk

                        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.