I need to protect URL alias from being submitted.
I've tried setting #disabled, #access, unset(), and what not. It hides the form, but the user is still able to modify the form on the client-side and submit it.
How do I prevent this form from being submitted on the client-side?
My current module code
<?php
function mymodule_form_alter(&$form, &$form_state){
if (empty($form['type']['#value'])) return;
$form['#after_build'][] = 'mymodule_after_built';
}
function mymodule_after_built($form, &$form_state) {
$form['path']['#access'] = FALSE;
$form['path']['alias']['#access'] = FALSE;
$form['path']['alias']['#value'] = $form['path']['alias']['#default_value'];
return ($form);
}
UPDATE:
To clear the question, I am not asking how to hide the form, but how to prevent the end-user from manually altering the code and submitting the form I just hid.
End-user can just edit source code and add <input type="text" id="edit-path-alias" name="path[alias]" value="" size="60" maxlength="255" class="form-text">
and still enter the alias.
hook_form_alter
directly? I mean, a whole vertical tab. Try. And if you try and fail, post the code you tried. Make sure you inspect form's structure first, withkpr
,var_dump
or something.unset($form['path'])
inhook_form_alter
. As far as I know, it's not possible to unset the form inhook_form_alter
, unless attaching it to#after_built
.$form['path']
? 2) What exactly happened when you tried?path_form_alter
, it's not accessible inhook_form_alter
, which is why#after_built
seems like it's the only way to override it.