Support » Plugin: Custom Content Type Manager » [Plugin: Custom Content Type Manager] Formatting a Text Field for numbers

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor fireproofsocks


    Do you want to enforce that in the manager? So basically you want data validation in the manager? That’s not implemented yet. See

    If you want to do this in your templates, then just use the PHP, just like you outlined. Just get the value using the get_custom_field() function and then have your way with the value it returns.

    Enforcing it in the manager, or more specifically, on the form itself, seems the prudent route. I’m new to CCTM so I don’t fully understand how you have implemented the admin form. Are the form inputs saved in a database table, called when a user clicks the ‘Add New’ button? Or is an actual form built and saved as a php template?

    I looked for the custom form I created but found no page with that name. So if these are database entries could I use a query to alter the value without breaking the output?

    Plugin Contributor fireproofsocks


    The CCTM uses built-in WP functionality and built-in WP tables, so it’s not doing anything different than WP here — it’d be the exact same behavior if you did not activate CCTM and you manually added custom fields to a post. WP does not standardize the custom fields, and it only offers support for text fields, so CCTM offers a lot of improvements there. WP unfortunately has no events that allow for real validation of the submitted forms — the closest you can come is to check the submitted data and force the status of the page to “draft” if the input didn’t validate (as outlined in Issue 6 above). This is one area where you can see the limits of the underlying WP architecture.

    To your question, the way that the form is generated is this:
    1. the custom fields meta box is handled by the CCTM (I’m replacing the default WP meta box here and forcing the custom fields to be standardized and support all those different input types).
    2. The html in that meta box is generated by the various form element classes (located in the CCTM’s folder: includes/elements). These are PHP files that follow a pattern: each time the form element is printed into the meta box, it is calling the respective PHP class’s “get_edit_field_instance” function. E.g. a colorselector field would generate the HTML for the colorselector input via the get_edit_field_instance() function inside of the includes/elements/colorselector.php file.

    The HTML that is used by that function can be customized without editing the core, but I haven’t documented that yet (I’m still tweaking it for 0.9.5), but it will let you customize the HTML that shows up in the manager. Issue 6 will incorporate other PHP classes that handle the custom validation, but that probably won’t be implemented until 0.9.6 or 0.9.7… still a couple months off, but the idea is that I’ll ship it with a set of common validation functions, and tech-savvy users can add their own PHP classes to implement their own validation functions (like the one you outlined).

    But right now, custom validation or input formats is not possible, and after looking at the dilapidated shape of the underlying WP code, I know that implementing this functionality will be an uphill battle. If you wanted to fund the development of that feature, I could send you a quote, otherwise maybe we could start up something with and get enough people in on it to get me to prioritize it.

    Another option is to use your own custom field — what’s required there is that you copy one of the existing field PHP classes and you would just have to implement the necessary functions. I’ve got this working in 0.9.5 (which will be available soon — you can try the dev version), but basically the CCTM will look in your own custom directory for any PHP classes, and you’ll be able to create your own “currency” field (as an example). There’s another function that fires to filter the data as it gets saved, so you could implement your filtering controls there in PHP.

    3rd option would be to add custom Javascript to manipulate the input to a given field. You could add code to the CCTM manager.js file, but I think there’s a better place for that sort of thing… I think WP will include a js file for the admin, and you could do your JS validations there.

    Otherwise, I’d really recommend MODX ( for this type of thing. It’s architecture is so much cleaner, and all of this stuff is built into the core very cleanly. The CCTM plugin is sorta just crumbs from MODx’s table.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Custom Content Type Manager] Formatting a Text Field for numbers’ is closed to new replies.