Jump to content

Prefill a field with a default value


neonwired
 Share

Recommended Posts

Is there a way to prefill a field with a default value.

I have a simple text field that 99% of the time will contain the same text but for the other 1% it needs to be editable so rather than paste in the same text for nearly every page I'm trying to find away to prefill the value of the input.

Link to comment
Share on other sites

The field has an option for a default value though it will only apply to newly created pages (in case you have previously created some of them).

My bad, this does not exist haha, I think only integer has this. But you could certainly do this with an "after hook" on ProcessPageEdit::buildForm and edit the value of the field in question. I dont have an immediate example but there is probably some around the forum

Link to comment
Share on other sites

You could edit the output in the template file and use the new $page->if() method.

https://processwire.com/api/ref/page/if/

So there might be no real need in setting a real value. Add a note or description to tell and explain editors the field behaviour.

You could define that default value somewhere in your config.php or even in a dedicated settings page to keep it editable - at least for superusers.

 

  • Like 2
Link to comment
Share on other sites

22 hours ago, wbmnfktr said:

You could edit the output in the template file and use the new $page->if() method.

https://processwire.com/api/ref/page/if/

So there might be no real need in setting a real value. Add a note or description to tell and explain editors the field behaviour.

You could define that default value somewhere in your config.php or even in a dedicated settings page to keep it editable - at least for superusers.

 

Thanks, that's one way if i can't hook something. It'd be nice to have a default field though.

  • Like 2
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...