Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

How to include a class field value in from template?


3 Posts   647 Views


Community Member, 82 Posts

10 January 2013 at 1:48am

Edited: 10/01/2013 1:51am


I have a langing page with a form that uses in it's action attribute a form handler url from an external API. The API takes the form fields values and redirects the user on another "Thank you" page on the same site.

I added a new text field to the LandingPageForm.php class to store the value of the "form handler url". I'm trying to call it from the form template in action attribute with <% control LandingPageForm %>$FormHandlerURL<% end_control %>, but this didn't show any value. This is the code I have:


class LandingPageForm extends Page
   static $db = array(
      'FormHandlerURL' => 'Text' // the form handler URL

   function getCMSFields()
      $fields = parent::getCMSFields();
      $fields->addFieldToTab("Root.Content.Main", new TextField('FormHandlerURL', 'Form handler URL'));
      return $fields;   


class LandingPageForm_Controller extends Page_Controller
   static $allowed_actions = array(
   //The function which generates our form
   function LandingPageForm()
   // Create fields
    $fields = new FieldSet(
       new TextField('FirstName', 'First Name'),
       new TextField('LastName', 'Last Name'),
       new EmailField('Email', 'Email')
    // Create action
    $actions = new FieldSet(
       new FormAction('SendLandingPageForm', 'Send me an intro package')
      // Create action
      $validator = new RequiredFields('FirstName', 'LastName', 'Email');
    $form = new Form($this, 'LandingPageForm', $fields, $actions, $validator);
    return $form;
   function SendLandingPageForm($data, $form) {


<form id="Form_LandingPageForm" action="<% control LandingPageForm %>$FormHandlerURL<% end_control %>" method="post" enctype="application/x-www-form-urlencoded">

   <% if Message %>
   <p id="{$FormName}_error" class="message $MessageType">$Message</p>
   <% else %>
   <p id="{$FormName}_error" class="message $MessageType" style="display: none;"></p>
   <% end_if %>

         <label class="left" for="Form_LandingPageForm_FirstName">First Name</label>
         <input type="text" class="text" id="Form_LandingPageForm_FirstName" name="firstname" placeholder="First Name *" value="">
         <label class="left" for="Form_LandingPageForm_LastName">Last Name</label>
         <input type="text" class="text" id="Form_LandingPageForm_LastName" name="lastname" placeholder="Last Name *" value="">
         <label class="left" for="Form_LandingPageForm_Email">Email</label>
         <input type="text" class="text" id="Form_LandingPageForm_Email" placeholder="Email *" name="email" value="">
         <input class="hidden nolabel" type="hidden" id="Form_LandingPageForm_SecurityID" name="SecurityID" value="911284708">
      <div class="clear"><!-- --></div>
   <% if Actions %>
   <div class="Actions">
      <% control Actions %>
      <% end_control %>
   <% end_if %>
   <p class="notice">We will never share your private information.</p>

I appreciate you help, thanks.



Forum Moderator, 5513 Posts

10 January 2013 at 5:43pm

Try <% control Controller %>$FormHandlerURL<% end_control %> as that will change your scope to the controller (where your FormHandlerURL variable is.


Community Member, 82 Posts

27 January 2013 at 7:47am

Thanks it's working now..