Answers.Body: <p>You can grab the content of a field for an element with</p>
  
  <pre><code>$myTableField = $entry-&gt;getContent()-&gt;getAttribute('fieldHandle');
  </code></pre>
  
  <p>You can modify the variable and send it back with </p>
  
  <pre><code>$entry-&gt;getContent()-&gt;setAttribute('fieldHandle', $myTableField);
  </code></pre>
  
  <p>Since you are probably in an event you should make sure your entry has the correct type and the correct section</p>
  
  <pre><code>$entry-&gt;getSection()-&gt;handle === 'mySectionHandle' &amp;&amp; $entry-&gt;getType()-&gt;handle === 'typeHandle'
  </code></pre>
  
  <p>If you want to change every table field and not just a certain one you can do</p>
  
  <pre><code>foreach($entry-&gt;getFieldLayout()-&gt;getFields() as $field){
      if($field::class === 'insert the class of the field here'){
          $table = $entry-&gt;getContent()-&gt;getAttribute($field-&gt;handle);
     } 
  } 
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T11:36:22.667Z
Answers.Text: I'm not sure this is the way to solve it. Perhaps I put in little information about the problem. I updated the question. Anyway I've tested it with your approach and the email address field was empty when sending email.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T12:02:11.843Z
Answers.Text: You can grab all available attributes for the element with `$entry->getContent()->getAttributes()` maybe you tried to access the wrong field handle? However you should have mentioned you are using the guest entry plugin. Maybe this one handles everything differently. I don't know it. My explanation is only for Craft
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T12:13:46.000Z
Answers.Text: I'm carefully with handles. I'll keep digging. Thank you for your time @Robin Schambach
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T10:57:32.893Z
Answers.LastActivityDate: 2018-05-18T11:03:12.110Z
Answers.LastEditDate: 2018-05-18T11:03:12.110Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm going through(learning) class reference <a href="https://docs.craftcms.com/api/v2/fieldtypes/TableFieldType.html" rel="nofollow noreferrer">TableFieldType in Craft 2</a> and I'm having trouble pulling out the value from a table field and save it as variable. I'm not sure I've started with the right approach.</p>
  
  <p>This is the piece of code I'm working on where contact details are saved to the table field. The problem starts when I need to get the email address value from that table field and use it further on.</p>
  
  <pre><code>public function init()
  {
      craft()-&gt;on('guestEntries.success', function (GuestEntriesEvent $event)
      {
  
          /** @var EntryModel $entryModel */
          $entryModel = $event-&gt;params['entry'];
  
          if($entryModel-&gt;getSection()-&gt;handle === "orderId")
          {
  
            $emailSettings = craft()-&gt;email-&gt;getSettings();
            $email         = new EmailModel;
            $emailAddress = '';
  
            // Questionable, not complete block of code 
            // Get value of "emailAddress" singleline type column from the "contactDetails" table field type
            foreach ($entryModel-&gt;getFieldLayout()-&gt;getFields() as $fieldLayout)
            {
              $field = $fieldLayout-&gt;getField();
  
              if ($field-&gt;getFieldType()-&gt;getName() == Craft::t('Table'))
              {
  
                foreach ($entryModel-&gt;{$field-&gt;myHandle}-&gt; ??? as $input)
                {
                   $emailAddress = $input-&gt;???;
                } 
              }
            }
  
            $email-&gt;toFirstName = $entryModel-&gt;getAuthor()-&gt;firstName;
            $email-&gt;toLastName  = $entryModel-&gt;getAuthor()-&gt;lastName;
  
            // Test if email address from "contactDetails" table field is present
            $email-&gt;toEmail     = !empty($emailAddress) ? $emailAddress : $entryModel-&gt;getAuthor()-&gt;email;
  
            $email-&gt;fromEmail   = $emailSettings['emailAddress'];
            $email-&gt;replyTo     = $emailSettings['emailAddress'];
            $email-&gt;sender      = $emailSettings['emailAddress'];
            $email-&gt;fromName    = craft()-&gt;config-&gt;get('siteName');
            $email-&gt;subject     = craft()-&gt;config-&gt;get('siteName') . " - New order received";
            $email-&gt;body        = "...";
            craft()-&gt;email-&gt;sendEmail($email);
  
          }
  
      });
  }
  </code></pre>
  
Tags: <plugin-development>
Title: How do I access table field type value?
ThreadText: # How do I access table field type value?
  
  (Asked by: username_0 on 2018-05-18)
  
  I'm going through(learning) class reference [TableFieldType in Craft 2](https://docs.craftcms.com/api/v2/fieldtypes/TableFieldType.html) and I'm having trouble pulling out the value from a table field and save it as variable. I'm not sure I've started with the right approach.
  
  This is the piece of code I'm working on where contact details are saved to the table field. The problem starts when I need to get the email address value from that table field and use it further on.
  
  ```
  public function init()
  {
      craft()->on('guestEntries.success', function (GuestEntriesEvent $event)
      {
  
          /** @var EntryModel $entryModel */
          $entryModel = $event->params['entry'];
  
          if($entryModel->getSection()->handle === "orderId")
          {
  
            $emailSettings = craft()->email->getSettings();
            $email         = new EmailModel;
            $emailAddress = '';
  
            // Questionable, not complete block of code 
            // Get value of "emailAddress" singleline type column from the "contactDetails" table field type
            foreach ($entryModel->getFieldLayout()->getFields() as $fieldLayout)
            {
              $field = $fieldLayout->getField();
  
              if ($field->getFieldType()->getName() == Craft::t('Table'))
              {
  
                foreach ($entryModel->{$field->myHandle}-> ??? as $input)
                {
                   $emailAddress = $input->???;
                } 
              }
            }
  
            $email->toFirstName = $entryModel->getAuthor()->firstName;
            $email->toLastName  = $entryModel->getAuthor()->lastName;
  
            // Test if email address from "contactDetails" table field is present
            $email->toEmail     = !empty($emailAddress) ? $emailAddress : $entryModel->getAuthor()->email;
  
            $email->fromEmail   = $emailSettings['emailAddress'];
            $email->replyTo     = $emailSettings['emailAddress'];
            $email->sender      = $emailSettings['emailAddress'];
            $email->fromName    = craft()->config->get('siteName');
            $email->subject     = craft()->config->get('siteName') . " - New order received";
            $email->body        = "...";
            craft()->email->sendEmail($email);
  
          }
  
      });
  }
  
  ```
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-18. Score: 1
  
  You can grab the content of a field for an element with
  
  ```
  $myTableField = $entry->getContent()->getAttribute('fieldHandle');
  
  ```
  
  You can modify the variable and send it back with
  
  ```
  $entry->getContent()->setAttribute('fieldHandle', $myTableField);
  
  ```
  
  Since you are probably in an event you should make sure your entry has the correct type and the correct section
  
  ```
  $entry->getSection()->handle === 'mySectionHandle' && $entry->getType()->handle === 'typeHandle'
  
  ```
  
  If you want to change every table field and not just a certain one you can do
  
  ```
  foreach($entry->getFieldLayout()->getFields() as $field){
      if($field::class === 'insert the class of the field here'){
          $table = $entry->getContent()->getAttribute($field->handle);
     } 
  } 
  
  ```
  
  > **Comments:**
  > **username_0**: I'm not sure this is the way to solve it. Perhaps I put in little information about the problem. I updated the question. Anyway I've tested it with your approach and the email address field was empty when sending email.  
  > **username_1**: You can grab all available attributes for the element with `$entry->getContent()->getAttributes()` maybe you tried to access the wrong field handle? However you should have mentioned you are using the guest entry plugin. Maybe this one handles everything differently. I don't know it. My explanation is only for Craft  
  > **username_0**: I'm carefully with handles. I'll keep digging. Thank you for your time @username_1  
  
  ---
  
  