Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Required form fields for write tab
To write tab :
Is there a solution to make form fields required (custom fields or article image for ex.) if article has the live status ?
If the status is draft, the field is not required.
Thanks
Offline
Re: Required form fields for write tab
Hi sacripan
Can javascript can do the trick? trigger save button and test if it s live or draft and check the custom field to see if it s empty!
A+
Offline
Re: Required form fields for write tab
Using jQuery… (not tested)
$('#article_form').submit(function() {
var goahead = true; /*by default submit the form*/
/*custom javascript to check values of fields. For example:*/
if ($('#custom-1').val()=""){
goahead = false; /*nothing in custom field 1 so set goahead to false*/
}
return goahead;
});
You could use bot_write_tab_customize or jmd_admin_js to implement something like this.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Required form fields for write tab
@MattD,
Thank you for the snippet, I have to test if I have no better.
@All
Yes, of course, I can add an overlay Javascript.
But Textpattern is a php CMS, right ?
Validating a form with only Javascript? In this case it is a lesser evil.
Ok, I lacked precision. Is there a php solution (plug’in?), To add validation options for the write form?
Offline
Re: Required form fields for write tab
sacripant wrote:
Is there a php solution (plug’in?), To add validation options for the write form?
Not yet, but I think it’s possible. A plugin can hook into the Write tab’s article save event/step using pre="1"
so the plugin is called before Txp’s built in routine. You could then do your validation rules and (probably) bomb out if they are not met.
I’m not sure how successful it would be as I don’t know how easy it would be to bypass Txp’s save step which would come immediately after the plugin finishes. It would probably involve some code duplication as you’d have to display the Write tab yourself and put your own message in like “custom_field ‘name’ needs to be filled in”, then you’d have to terminate the code so it didn’t run Txp’s built-in save.
It might be simpler than that — maybe just making sure the txp_article.php file is present and calling the function to display the write tab manually with the given message string — but I’ve never really looked into it.
Last edited by Bloke (2011-12-14 10:44:47)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Pages: 1