2017 © Pedro Peláez
 

concrete5-package attribute_free_form

image

remo/attribute_free_form

  • Monday, January 9, 2017
  • by Remo
  • Repository
  • 3 Watchers
  • 1 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Attribute Free Form

A concrete5.7 attribute you can use to quickly create your own attribute types., (*1)

When you add a free form attribute, you've got two fields, one where you specify the form you'll see when you enter some data and a view form you'll see when the data is presented to the end-user., (*2)

In order to to save and load fields you have to use specific names which will be replaced at runtime., (*3)

Example 1 - Simple field

edit form:, (*4)

<strong>Name:</strong>
<input type="text" name="[ATTRIBUTE(Name)]" value="[ATTRIBUTE_VALUE(Name)]">

view:, (*5)

<strong>Name:</strong>
[ATTRIBUTE_VALUE(Name)]

Example 2 - Hidden fields with JavaScript

edit form:, (*6)

<input type="hidden" name="[ATTRIBUTE(Lat)]" value="[ATTRIBUTE_VALUE(Lat)]" id="lat"><br>
<input type="hidden" name="[ATTRIBUTE(Long)]" value="[ATTRIBUTE_VALUE(Long)]" id="long"><br>



Address:

view:, (*7)

<div>
    <strong>Address</strong>[ATTRIBUTE_VALUE(Address)] ([ATTRIBUTE_VALUE(Lat)] / [ATTRIBUTE_VALUE(Long)])
</div>

Example 3 - Access fields programmatically

Assuming you've got the form in place from the first example using an attribute handle of test_attribute. If you want to work with the attribute fields from a custom theme or another concrete5 method, you can use the following approach., (*8)

// get the page we want to work with
$p = \Page::getByID(1);

// show attribute view
echo $p->getAttribute('test_attribute');

// get value of our attribute field called "Name"
$values = $p->getAttribute('test_attribute', 'variables');
echo $values['Name'];

Example 4 - Save fields programmatically

If you want to write the values of this attribute you can simply call the setAttribute method with an array as its parameter., (*9)

// get the page we want to work with
$p = \Page::getByID(1);

// show attribute view
$p->setAttribute('test_attribute', ['Name' => 'Remo']);

The Versions

09/01 2017

dev-master

9999999-dev

  Sources   Download

The Requires