Closed (duplicate)
Project:
Metatag
Version:
7.x-1.0-alpha6
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Sep 2012 at 20:36 UTC
Updated:
27 Dec 2012 at 12:44 UTC
Hi.
I am working with the meta tags module and I need the field Keywords and field Description be required or mandatory and the field Title be optional in a specific content type. How can I do it?
Thanks.
Comments
Comment #1
damienmckennaTry hook_form_alter?
Comment #2
cabita commentedHi,
I found to do the fields mandatory or required. Now I have troubles for put styles. I need that the fields Keywords and Description look like as : http://screencast.com/t/cpbs2EJAgZD
I don't know how can I put the * symbol to the labels "Keywords" and "Description" and I don't know how can I do for the red border only is around the field of the box.
The code worked is the follow and validate the fields without styles:
mymodule_form_alter(&$form, &$form_state, $form_id) {
$form_id = $form['form_id']['#value'];
if ($form_id == "article_node_form") {
$form['#validate'][] = 'mymodule_test_validation';
}
}
function mymodule_test_validation($form, &$form_state) {
if (($form_state['values']['metatags']['description']['value'] == '')) {
form_set_error('Description', t('field is required'));
}
if (($form_state['values']['metatags']['keywords']['value'] == '')) {
form_set_error('Keywords', t('field is required'));
}
}
Also I tried this option but doesn't work:
mymodule_form_alter(&$form, &$form_state, $form_id) {
$form_id = $form['form_id']['#value'];
if ($form_id == "article_node_form") {
// Make META DESCRIPTION required
$form['metatags']['description'] = array('#require' => TRUE,);
// Make META KEYWORDS required
$form['metatags']['keywords'] = array('#require' => TRUE,);
}
}
If I put the last code, the tab metatags disappears, if I add
$form['#metatags']['metatags']['description'] = array('#require' => TRUE,);
instead of
$form['metatags']['description'] = array('#require' => TRUE,);
the tab metatags appears but the fields are not validated.
Thanks for your help.
Comment #3
damienmckennaOk, so editing Metatag's fields is not as simple as I alluded to, you can't just hook_form_alter() it because of how the fields are inserted. I'll have to get back to you on the best way of doing it.
Comment #4
cabita commentedThanks. I look forward your answer.
Comment #5
damienmckennaDuplicate of #1391968: Document how to disable/modify meta tags.
Comment #6
fietserwinAs the issue turned into a documentation issue, I want to point out some flaws in the code of #2 as well as possible optimizations/generalizations:
Comment #7
remkovdz commentedCan anybody help with the code to make the description field mandatory? I'm not a developer but really need the function. :( Thanks!