I discovered Covert Fields while searching for a way to enter regex validated links. I don't know PHP but the regex validation example provided in a previous issue was quite easy to follow. After the input passes validation, how could it be displayed as a clickable link? (I guess that support for the Link CCK field would be harder to implement...) Thank you.

Comments

john.karahalis’s picture

Thanks for the interest, skizzo. I'm glad to see you learned some PHP by adding regex validation---PHP is a great language to know if you're going to be working with Drupal. Congratulations!

To display your field as a link, you can edit the field settings (Administer > Content Types > Manage Fields) and combine the HTML a tag with a little PHP for the "Code for Displayed Value".

For example, the following could be used to display a link to example.com with your stored value as the text for the link.

return '<a href="http://example.com">' . $stored_value . '</a>';

Hope that helps. Let us know if you get it working.

skizzo’s picture

Thank you for helping me out! And yes, I got it working... but I guess I do not fully understand
stored/displayed values. Here is my textfield setting (filtered HTML input format being enabled):

[stored] return $entered_value;
[displayed] return '<A href=http://example.site.com/' . $stored_value . ' >' . $stored_value . '</A>'

At first run it works nicely. Problem is that whenever the node is saved again the displayed value
acts as a new entered value, recursively being appended to the original value. Would it make sense
for Covert Fields to load the stored value (rather than the displayed value) in form editing?

john.karahalis’s picture

One approach would be to use something like the following, which would only customize the display on pages that are not the edit page.

// Return the custom display only if the user is not on the edit page.
if(arg(2) != 'edit') {
  return '<a href="http://example.com">' . $stored_value . '</a>';
}
kiwad’s picture

john.karahalis' workaround sounds a good idea and could maybe extended. in my case i'm using it with a user reference. User enters an email address and, if it is a valid user the stored value is UID, so I'll would do a something like that in my Code for Displayed Value :

//Draft code - not tested
// Return the email if it is on the edit page.
if(arg(2) == 'edit') {
  $email=db_result(db_query("SELECT mail FROM users WHERE (uid=%d)", $stored_value));
return $email;
}
// else, return a link to user profil and display the realname of the user with the module realname
else {
  $name=db_result(db_query("SELECT realname FROM realname WHERE (uid=%d)", $stored_value));
return '<a href=http://example.com/user/' . $stored_value . ' >' . $name . '</a>';
}