Blog

BranchCMS Upgrades

Eric Tompkins
Jul 18, 2015

More Customization Options With the Form API Tag

There are times when it would be nice to programmatically set the value for a form field when displaying it on a page. A recent release now lets you do that through the form's API tag

Before we get into the details let me give you an example first.

Let's say that you have a few product pages and you want to place a small lead-generation form on those pages for prospective customer's to easily contact you for more information. The form is a simple one with fields for their name, email and phone number. In order for the form to really be useful, though, it would be great to know what product that the customer was interested in. You could add a field for them to fill out with the name of the product but that seems weird and makes your website look like it's not very smart. It would be best to have a hidden form field where you can specify the name of the product individually on each page.

It's now really easy to do that. 

There is a new parameter for the form API tag called "field" that lets you set a number of form field tag attributes or field properties, like the field's value.

Let's say that our form is called "Contact" with a form key of "contact". We have a hidden field call "Product or Service" with a field key of "productService". Here is how we would specify the value of that hidden field using the form API tag. In this example our product is called "Ultimate Chocolate Deluxe Bars".

{ap_api:form:getForm key="contact" field[productService][value]="Ultimate Chocolate Deluxe Bars"}

Learn more about the form API tag 'field' parameter in the Branch CMS documentation.

Sign up for our newsletter to receive invaluable information about BranchCMS, web design & development.