remo / attribute_free_form
本包的最新版本(dev-master)没有提供许可证信息。
dev-master
2017-01-09 18:14 UTC
Requires
- php: >=5.4
- composer/installers: ~1.0.7
This package is not auto-updated.
Last update: 2024-09-14 17:53:37 UTC
README
一个 concrete5.7 属性,可用于快速创建自己的属性类型。
当你添加一个自由表单属性时,你将有两个字段,一个用于指定你输入数据时看到的表单,另一个用于数据向最终用户展示时的表单。
为了保存和加载字段,你必须使用特定的名称,这些名称将在运行时被替换。
示例 1 - 简单字段
编辑表单
<strong>Name:</strong> <input type="text" name="[ATTRIBUTE(Name)]" value="[ATTRIBUTE_VALUE(Name)]">
查看
<strong>Name:</strong> [ATTRIBUTE_VALUE(Name)]
示例 2 - 使用 JavaScript 隐藏字段
编辑表单
<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> <div> Address: <input type="text" name="[ATTRIBUTE(Address)]" value="[ATTRIBUTE_VALUE(Address)]" id="address"><br> </div> <script type="text/javascript"> $(document).ready(function() { $("#address").on("change", function() { var address = $(this).val(); $.ajax({ url:"http://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&sensor=false", type: "POST", success:function(res){ lat = res.results[0].geometry.location.lat; long = res.results[0].geometry.location.lng; $("#lat").val(lat); $("#long").val(long); } }); }); }) </script>
查看
<div> <strong>Address</strong>[ATTRIBUTE_VALUE(Address)] ([ATTRIBUTE_VALUE(Lat)] / [ATTRIBUTE_VALUE(Long)]) </div>
示例 3 - 以编程方式访问字段
假设你已经从第一个示例中创建了表单,并使用属性处理程序 test_attribute
。如果你想从自定义主题或另一个 concrete5 方法中处理属性字段,可以使用以下方法。
// 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'];
示例 4 - 以编程方式保存字段
如果你想写入此属性的值,可以简单地调用带有数组参数的 setAttribute
方法。
// get the page we want to work with $p = \Page::getByID(1); // show attribute view $p->setAttribute('test_attribute', ['Name' => 'Remo']);