1

Hey I'm writing my first Craft plugin and would like to add a button to have a dialog box in Choose an entry. I want to create a link to a page entry with this and save it to the database.

This is the code I want to extend in my template:

{% import "_includes/forms" as forms %}

    <div class="" style="width: 50%">
        <form method="post" action="" accept-charset="UTF-8">
            <input type="hidden" name="action" value="glossary/entry/saveEntry">
            <input type="hidden" name="redirect" value="glossary">
            {{ forms.textField({
               label: 'Glossary Entry'|t,
               instructions: 'Enter a new Word'|t,
               id: 'entry',
               name: 'entry',
               value: ''}) }}
            <input class="btn submit" type="submit" value="{{ 'Submit'|t }}">
        </form>
    </div>

1 Answer 1

3

I believe what you need is the elementSelect field type which Craft bundles with the CMS. You can find the template of this field in craft/app/templates/_includes/elementSelect.html

Here's a quick example that will get you started:

{{ forms.elementSelectField({
    label: 'Select An Entry'|t,
    instructions: 'Select...'|t,
    id: 'entry',
    name: 'entry',
    elementType: craft.elements.getElementType("Entry"),
    source: '',
    criteria: '',
    sourceElementId: '',
    elements: '',
    storageKey: '',
    viewMode: 'list',
    limit: 1
 }) }}
2
  • Thanks i'll check that! Where is the doc for this stuff? Commented Oct 7, 2016 at 13:55
  • @SimonMüller No problem. As far as I know there isn't any, it's just from my experience of reverse engineering these fields previously. Commented Oct 7, 2016 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.