19
votes
Accepted
How to add custom user fields to the front end registration page
You need to change your input tag from:
<input id="Address" type="text" name="Address"
{%- if account is defined %} value="{{ account.Address}}"{% endif -%}>
To:
<input id="Address" type="...
13
votes
Accepted
Is it possible to output the name of a Matrix Block?
block.type is actually an alias for a getType() function, which returns a new MatrixBlockTypeModel object. Those will output their handle by default, which is why it's possible to compare block.type ...
12
votes
Accepted
How can I update custom order fields in the frontend
Correct, you need to use fields[customFieldName] as the input name.
The following form should do it:
<form method="POST">
<input type="hidden" name="action" value="commerce/cart/...
10
votes
How can I limit a list based on a custom date field
Actually you should be able to specify your custom field as part of the chained element criteria:
{% set currentAndFutureEvents = craft.entries.section('events').eventDate('>= ' ~ now).order('...
7
votes
Accepted
How can I limit a list based on a custom date field
I think .after would work, but I've used this way:
{% set entries = craft.entries.section('events').limit(null) %}
{% for entry in entries.eventDate('>=' ~ (now.date)).order('eventDate DESC') %}
...
6
votes
Display thumbnail using defineTableAttributes for a custom Element Type
Ok, so I've managed to get an answer to this courtesy of Brandon Kelly. It's much more simple than I thought. Firstly, you do not have to specify a relatedTo parameter the defineCriteriaAttributes()....
6
votes
Accepted
How does a plugin make use of Craft's storage?
craft/storage/ is used for all sorts of things, so there’s no single API for storing things in there. Mostly you would just be working with PHP’s standard IO functions like file_put_contents(). There ...
6
votes
Accepted
"Excerpt" option in Redactor?
You could use the Redactor's pagebreak plugin. Check out the docs.
If activated in your Redactor config, you will have the option to insert page breaks to your content, via a new “Insert Page Break” ...
6
votes
Accepted
How is Craft able to reuse fields in different Sections? (As opposed to EE.)
In Craft, all fields are stored in the craft_content table. They are otherwise independent of any field groups, layouts, sections, or anything else.
PRO: This means that any element (Entry, Category, ...
6
votes
Accepted
Display custom product field in cart
You could set a variable to access the products model like so:
{% set product = item.purchasable.product %}
and then access the fields like normal {{ product.myCustomField }}
The snapshot holds the ...
5
votes
Accepted
Best way to use custom enums in my plugin templates?
Right now that's probably the best way to do it.
For Craft 2.2, I just added a static getConstants() method to BaseEnum, so you can do can do a PluginStatus::getConstants() call that will return an ...
5
votes
Craft's Content Table
A huge boon to Craft is the ability to re-use fields across all your content – sections, categories, entry types or even users. The field groups are basically only there to make it easier for you to ...
5
votes
Craft's Content Table
MySQL has a hard coded limit of 4,096 columns per table, although that can be effectively limited by the data types of columns involved.
Matrix fields get their own tables, so they don't count ...
4
votes
Accepted
Return entries where custom field partially contains
You could use the Preparse plugin to save the product ID part of your field in a new hidden field.
Add a new "productId" Preparse field to your entry type with this code in the field's settings:
{{ ...
4
votes
Accepted
How to pull out all user data in a template?
If i understand your question correct, you like to output the user data. I don't think that you need the getContent() function. But it's important, that you use the first() function. Here is your code:...
4
votes
How do I set the value of a custom entries order field from a plugin?
I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field.
Since an entries field is an array of elements, not just a single element, I just needed to ...
4
votes
Unable to store Model in Commerce Order Fields
When you assign element IDs to a relation field you need to pass the data in an array format.
See this related answer: In a plugin, how do I save an entry with a related entry
Key information in ...
4
votes
Accepted
date in database -1 day as on frond-end
The database will be storing the date as seconds since 1970 (epoch) and your view on that is not localised. However, the front end date is localised for your time zone.
Of this I am more sure than ...
4
votes
How to save a new entry with custom fields - Craft 3
It turns out the data wasn't being saved as I hadn't set a fieldLayoutId value.
Now that I've figured this out, I've written a helper method to make saving any entry type much easier:
public static ...
4
votes
Accepted
Adding Columns to a table
With the supercool table maker you can create dynamic tables. Is this what you are looking for?
3
votes
Accepted
How to check custom field not empty within params?
You’re just missing the : at the end of :notempty: in your second example. This will work:
{% set params = { section: 'sectionName', customField: ':notempty:', limit: 10} %}
3
votes
Accepted
Custom field type that has multiple fields to extend the default field types
I would say you can do this yeah, it just take a little figuring out is all.
Your input template could look something like:
<input type="text" name="{{ name }}[title]" value="{{ value.title is ...
3
votes
Accepted
Why won't the values of an editableTableField show up in my template?
That string that Craft stores is just JSON. When you try to save an array, Craft will automatically JSON-encode it, since MySQL doesn’t have an array-based data type.
To get that string to be ...
3
votes
Can a model or record have conditional requirements?
I can think of a couple of options and I'll just throw them all out there.
Have a separate model per partial form and each model performs its own validation.
Have a single model, but have it override ...
3
votes
Accepted
customised slugs using custom field
Firstly I'd recommend splitting the first name and last name into seperate fields. That way in your templates it would look nicer:
{{ member.firstNameField }} {{ member.lastNameField }}
than having:
...
3
votes
Allow a dropdown custom field to be edit from a front end form
Just to make sure I am on the same page, you have a select field within the control panel that is populated with the prefix/title(s)?
If that's the case, within your registration form, you could do ...
3
votes
Accepted
Checking value of customer order field within Plugin
What you're probably looking for is:
if ($order->signupForNewsletter->contains('joinMailingList'))
{
echo "I've opted in";
}
else
{
echo 'Not matched';
}
3
votes
Accepted
More than one field for a fieldtype plugin
Nope – a single field can only have a single column in the craft_content table.
If you need your FieldType to save complex data, you have two options:
The easiest approach – by far – is to simply ...
3
votes
Accepted
Custom Field on Settings page
You can’t change or add fields to the General Settings page, but for site wide available content Craft has this concept of Globals.
See the documentation on it:
https://craftcms.com/docs/globals
It’...
3
votes
Option and notes fields after cart at checkout for order, not just line items
First, add a custom field to your orders, let's call it orderNotes.
Then, in any updateCart form, you can use an input with name="fields[orderNotes]" to set the value of that field.
(Line items ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
custom-field × 93custom-fieldtype × 20
plugin-development × 16
craft3 × 11
field × 11
plugin-craftcommerce × 10
users × 10
templating × 8
entries × 8
datetime × 6
fieldtypes × 5
validation × 5
modules × 4
table-field × 4
plugins × 3
entry × 3
form × 3
elementtype × 3
order × 3
assets × 2
database × 2
relations × 2
search × 2
structure × 2
error-message × 2