views:

265

answers:

1

I have an autocomplete nodereference field (field_hostnamelastref) in a custom pass-node-form.tpl.php. The field references four items (last name, first name, an id #, and status) generated from tokens in an autotitle from another content type.

When entering a last name in the nodereference field, if the corresponding status for that last name is "SUSPENDED", I would like to be able to validate that field with an error message and block form submission.

This is my first attempt at writing my own validation and am not having any luck. Have tried many different ways ereg, preg-match and strpos. Below is my latest attempt:

<?php
function pass_validate($form_id,$form_values) {
$status = 'SUSPENDED';
if (strpos ($form_values['hostnamelastref'], $status)) {
form_set_error('hostnamelastref', t('The account for this person has been suspended.', array('@type' => $type->name)));

} } ?>

Not sure if I'm even in the ball park on this. Any help much appreciated!

A: 

If you can pass the SUSPENDED information somehow to views, then you can limit the nodes one chooses in the nodereference using a view. Then nodereference will take care for validation if the user entered a node not in the list.

But I am not sure I understood your question.

yhager