Jump to content
neosin

how to create non editable field to show page ID in admin form?

Recommended Posts

I need to display the page id when view/edit a page in the admin, I am not sure how to do this.

Basically it is a field that the user cannot edit, it will show a url to the page with the id in it, like this; www.site.com/en/pageID

This is so CMS users can share the short url. I am using @adrian's redirect module to enable redirect using page IDs.

Share this post


Link to post
Share on other sites

ok this can be deleted, looking at @adrian's redirect module, it seems I need to create a hook in admin.php and then add the field to the form.

Sorry, still trying to muddle my way through PW lol

Share this post


Link to post
Share on other sites

@adrian thank you, I will use this runtime markup fieldtype

 

On a side note, using hooks how would you put a non editable field at the top of a form?

this is what I had come up with before seeing your reply above, the results are it gets added but under the save button.

For learning purposes, how would I make it added at the top of the existing form fields (if it is even possible)?

wire()->addHookAfter('ProcessPageEdit::buildForm', function($event) {
    $pp = wire('pages')->get(wire('input')->get->id);
    $form = $event->return;
    $field = wire('modules')->get("InputfieldMarkup");
    $field->label = 'TEST';
    $field->value = $pp;
    $form->append($field);
});

 

 

 

Share this post


Link to post
Share on other sites

@adrian tyvm

if anyone needs example of insert custom field before other form fields:

wire()->addHookAfter('ProcessPageEdit::buildForm', function($event) {
    $pp = wire('pages')->get(wire('input')->get->id);
    $form = $event->return;
    $field = wire('modules')->get("InputfieldMarkup");
    $field->label = 'TEST';
    $field->value = $pp;
    $field2 = $form->get('title'); // Field to find and insert new field "before" it
    $form->insertBefore($field,$field2);
});

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 4/12/2018 at 1:32 AM, neosin said:

@adrian tyvm

if anyone needs example of insert custom field before other form fields:


wire()->addHookAfter('ProcessPageEdit::buildForm', function($event) {
    $pp = wire('pages')->get(wire('input')->get->id);
    $form = $event->return;
    $field = wire('modules')->get("InputfieldMarkup");
    $field->label = 'TEST';
    $field->value = $pp;
    $field2 = $form->get('title'); // Field to find and insert new field "before" it
    $form->insertBefore($field,$field2);
});

 

If I'm adding a custom field I also take it that I'll need to create a schema etc to store the values?

Is there a way to adding abitry fields to a page in admin similar to notes, description fields without defining a schema?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...