Sean Dinwiddie Posted February 23, 2018 Share Posted February 23, 2018 What's the simplest code to have a field that will save? Thank you in advance! Kind regards, Sean Link to comment Share on other sites More sharing options...
LexSanchez Posted February 23, 2018 Share Posted February 23, 2018 Hi Sean: This is a basic example of how to create a module that has configurable fields. <?php class Example extends Process implements Module, ConfigurableModule { private static $pathDir; /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * * @return array * */ public static function getModuleInfo() { return array( // The module's title, typically a little more descriptive than the class name 'title' => 'Example Module', // version number 'version' => '0.0.1', // summary is brief description of what this module is 'summary' => 'This module descripton.', // author 'author' => 'Author Name', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, // If true, the module may not be uninstalled once installed. 'permanent' => false, 'page' => array( // optionally install/uninstall a page for this process automatically 'name' => 'example-module', // name of page to create 'parent' => '', // parent name (under admin) or omit or blank to assume admin root 'title' => 'Example Module', // title of page, or omit to use the title already specified above ), 'permission' => 'example-module', 'requires' => array('PHP>=5.4.1', 'ProcessWire>=2.7.0'), 'icon' => 'film', // module icon ); } public static function getModuleConfigInputfields(array $data) { // ------------------------------------------------------------------------ // Initialize InputField wrapper // ------------------------------------------------------------------------ $fields = new InputfieldWrapper(); // ------------------------------------------------------------------------ // Define text input field for the directory path. // ------------------------------------------------------------------------ $field = wire('modules')->get('InputfieldText'); $field->name = 'pathDirectory'; $field->label = __('Directory Videos'); $field->required = true; $field->columnWidth = 50; $field->value = (!empty($data['pathDirectory']) ? rtrim($data['pathDirectory'],"/")."/" : '/var/www/html/videos/'); $field->description = __('Description Field.'); $fields->add($field); // ------------------------------------------------------------------------ // Return of the fields. // ------------------------------------------------------------------------ return $fields; } public function ___install() { parent::___install(); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { // Variable from module settings self::$pathDir = $this->pathDirectory; } /** * Executed when root url for module is accessed * */ public function ___execute() { $preview = $this->modules->get("InputfieldMarkup"); $preview->value .= "<h2>echo " . $this->pathDirectory . "</h2>"; return $preview->render(); } } 3 Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 Right on, Lex. Will check this out! Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 Okay, so the Processhello module does have a savable text input field, but the input field is at the module's settings page; that might be good enough for now. Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 Well, here's a start: https://github.com/shastacom/BrandIdentity/ Link to comment Share on other sites More sharing options...
theo Posted February 23, 2018 Share Posted February 23, 2018 Hello, What is the purpose of this module? 1 Link to comment Share on other sites More sharing options...
bernhard Posted February 23, 2018 Share Posted February 23, 2018 I guess you might find my tutorial and blog post useful: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#handling-user-input-using-forms-amp-inputfields 1 Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 9 hours ago, theo said: Hello, What is the purpose of this module? This module eventually( as it gets developed ) will be for company/brand details. We have been using a special page with lots of custom fields. This will be more standardized. Thank you for asking. Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted February 23, 2018 Author Share Posted February 23, 2018 Thank you so much, Bernhard, for the very useful help. That is exactly what is needed. 1 Link to comment Share on other sites More sharing options...
bernhard Posted February 24, 2018 Share Posted February 24, 2018 glad it helped 1 Link to comment Share on other sites More sharing options...
Macrura Posted February 25, 2018 Share Posted February 25, 2018 Or use SettingsFactory for your settings page if it can support the fields you need. 1 Link to comment Share on other sites More sharing options...
Sean Dinwiddie Posted March 16, 2018 Author Share Posted March 16, 2018 Thank you, Macrura. Will need to look into that. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now