title: Submit form and prepopulate custom fields in DocuSign Envelope
body: <p>For some reason I can't get my code to show the custom fields I am wanting to add in the left pane(e.g. First Name, Last Name, etc.). On submit my form should go to the envelope and prepopulate my custom fields. I've searched the DocuSign docs and also different threads on here. Any help is much appreciated. Thank you.</p>
  
  <pre><code>&lt;?php
  if(!empty($_POST)){
      // Input your info:
      $email = "foor@bar.com";                                 // your account email
      $password = "password";                              // your account password
      $integratorKey = "wouldnt-you-like-to-know"; // your account integrator key, found on (Preferences -&gt; API page)
      $templateId = "66b7706e-936b-4438-bd5e-bd68ce47dffb";    // provide a valid templateId of a template in your account
      $templateRoleName = "Test";                              // use same role name that exists on the template in the console
  
      $recipientName = 'blah bleh';                        // provide a recipient (signer) name
      $recipientEmail = 'yee@haw.com';
                                                               // the recipient name and email.  Whatever you set the clientUserId to you must use the same
                                                               // value when requesting the signing URL
                                                               // construct the authentication header:
      $color = $_POST['color'];
      $number = $_POST['number'];
      $animal = $_POST['animal'];
  
      $header = 
      "&lt;DocuSignCredentials&gt;
          &lt;Username&gt;" . 
              $email . 
          "&lt;/Username&gt;
          &lt;Password&gt;" . 
              $password . 
          "&lt;/Password&gt;
          &lt;IntegratorKey&gt;" . 
              $integratorKey . 
          "&lt;/IntegratorKey&gt;
      &lt;/DocuSignCredentials&gt;";
  
      // STEP 1 - Login (retrieves baseUrl and accountId)
      $url = "https://demo.docusign.net/restapi/v2/login_information";
      $curl = curl_init($url);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
      $json_response = curl_exec($curl);
      $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  
      if ( $status != 200 ) {
          echo "&lt;br&gt;";
          echo "error calling webservice, status is:" . $status;
          exit(-1);
      }
  
      $response = json_decode($json_response, true);
      $accountId = $response["loginAccounts"][0]["accountId"];
      $baseUrl = $response["loginAccounts"][0]["baseUrl"];
      curl_close($curl);
  
      //--- display results
      echo "accountId = " . $accountId . "\nbaseUrl = " . $baseUrl . "\n" . "&lt;br&gt;";
  
      // STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
      $data = array(
          "accountId" =&gt; $accountId, 
          "emailSubject" =&gt; "DocuSign API - Embedded Signing Example",
          "emailBlurb" =&gt; "This is a test.",
          "compositeTemplates" =&gt; array(
              "serverTemplates" =&gt; array(
                  "sequence" =&gt; "1",
                  "templateId" =&gt; $templateId
              ),
              "inlineTemplates" =&gt; array(
                  "sequence" =&gt; "2",
                  "recipients" =&gt; array(
                      "signers" =&gt; array(
                          "roleName" =&gt; "Signer1",
                          "recipientId" =&gt; "1",
                          "name" =&gt; "John Doe",
                          "email" =&gt; "johndoe@test.com",
                          "clientUserId" =&gt; "1234",
                          "tabs" =&gt; array(
                              "textTabs" =&gt; array(
                                  "tabLabel" =&gt; "address",
                                  "value" =&gt; "123 Main Street"
                              )
                          )
                      )
                  )
              )
          ),
          "status" =&gt; "sent"
      );    
  
      $data_string = json_encode($data);  
      $curl = curl_init($baseUrl . "/envelopes" );
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
      curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
          'Content-Type: application/json',                                                                                
          'Content-Length: ' . strlen($data_string),
          "X-DocuSign-Authentication: $header" )                                                                       
      );
  
      $json_response = curl_exec($curl);
      $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  
      if ( $status != 201 ) {
          echo "error calling webservice, status is:" . $status . "\nerror text is --&gt; &lt;br&gt;";
          print_r($json_response); echo "\n";
          exit(-1);
      }
  
      $response = json_decode($json_response, true);
      $envelopeId = $response["envelopeId"];
      curl_close($curl);
  
      //--- display results   
      echo "&lt;br&gt;Envelope created! Envelope ID: " . $envelopeId . "\n"; 
  
      // STEP 3 - Get the Embedded Signing View 
      $data = array(
          "returnUrl" =&gt; "http://www.docusign.com/devcenter",
          "authenticationMethod" =&gt; "Email", 
          "clientUserId" =&gt; "1234",
          "userName" =&gt; "John Doe",
          "email" =&gt; "johnDoe@test.com"
      );   
  
      $data_string = json_encode($data);    
      $curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);                                                                  
      curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                          
          'Content-Type: application/json',                                                                                
          'Content-Length: ' . strlen($data_string),
          "X-DocuSign-Authentication: $header" )                                                                       
      );
  
      $json_response = curl_exec($curl);
      $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  
      if ( $status != 201 ) {
          echo "error calling webservice, status is:" . $status . "\nerror text is --&gt; ";
          print_r($json_response); echo "\n";
          exit(-1);
      }
  
      $response = json_decode($json_response, true);
      $url = $response["url"];
  
      //--- display results
      echo "\n\nNavigate to this URL to start the embedded signing view of the envelope\n" . "&lt;br&gt;Embedded URL is: \n\n" . "&lt;a href='$url'&gt;HERE!&lt;/a&gt;"; 
  }
  ?&gt;
  &lt;form action="" method="POST"&gt;
  &lt;label for="color"&gt;color:&lt;/label&gt;
  &lt;input type="text" name="color"&gt;
  &lt;br&gt;
  &lt;label for="number"&gt;number:&lt;/label&gt;
  &lt;input type="text" name="number"&gt;
  &lt;br&gt;
  &lt;label for="animal"&gt;animal:&lt;/label&gt;
  &lt;input type="text" name="animal"&gt;
  &lt;br&gt;
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;    
  </code></pre>