This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

Custom Node Validation - how to autocorrect user input?

In creating a custom node module, it is great that you can create a _validate function to check user input.

However, what would be *really* neat would be the ability to auto-correct (or auto format) some common user mistakes, rather than just giving them an error message.

For example, some of my modules requires the user to submit a URL. For consistency, I want these to always be in the format "www.domain.com/page.htm" and *not* include the leading "http://". Despite giving this field a description that says the "http://" should not be included, users will often just cut+paste a URL from their browser, thus including the "http://" bit that I don't want.

Sure, I can write a _validate function to check if the URL starts "http://" and return an error, but it would be much nicer to just "auto-correct" this simple mistake.

Until now I have done this by creating a custom function, and modified my hook_insert and hook_update functions to call it, something like this (very cut down for simplicity):


function mylib_strip_url($url) {
// strip leading "http://", if present
if (substr($url,0,7) == 'http://') {
$stripped_url = substr($url,7);
} else {
$stripped_url = $url;
}
return $stripped_url;
}

function mynode_insert($node) {
db_query("INSERT INTO {mytable} (nid, website) VALUES (%d, '%s')", $node->nid, mylib_strip_url($node->website));

put taxonomy_dhtml menu into a block

Can anyone help me on this. I wish to have the exact menu that is displayed when i visit my domain.com/taxonomy_dhtml page. I need this menu in a block. I have tried the block that comes with taxonomy_dhtml, but this doesn't act in the same way. I have also tried all the php snippets available for blog categories and alos taxonomy_menu.

How can i do this?

Custom Book Block Module

Hi, I just hacked a module that lets the admin define blocks that list any number of books along with a customizable number of subpages for each. Based on NICE_MENUS module, it relies on the JSTOOLS module and its child, ACTIVEMENU to do some AJAX. It is not perfect and I used 4 spaces instead of 2 for indentations... old habit. I thought some people might appreciate it... in the future I want to define permissions a little bit better. So here it is:

Get Form Variables

Hi Drupal- Users.

I am a total Drupal Newbee and at the moment i am try to develop a little form with the new form api, but i can't work with the sended form variables.

Here is my code:

Converting _nodeapi (4.6->4.7) and 2 text fields on one line

Dear Drupal Community,

After digging through the Converting 4.6 modules to 4.7, the hook_nodeapi for 4.6 and 4.7 API pages, the hook_nodeapi('form x', ...) replaced by form api section, the hook_user, and a multitude of searches along the lines of “HowTo convert a 4.6 module to a 4.7 module,” I'm stumped. I've managed to learn/thieve/borrow enough other code to get the other 700-800 lines of this modified AdSense module to work as desired, but the proper method for converting these two items continues to baffle me:

- Converting "function adsense_nodeapi(&$node, $op, $teaser, $page)"
[moved to separate thread in this post as this one got long with the Form Updater tidbits.]

- Placing two form text fields on a single line.
In the example below "Version 4.6.x: foreach(range(1,200)..." , while it has all the inherent drawbacks of embedded hardcoding, it did produce two text boxes on the same screen line. Is there anyway within the regular "$form['name'] = array(..." methodology to archive the same thing?

Can I impose on some nice coder to review/fix what I tried? Even if you would post an RTFM with a link to something that gives a concrete example on what exactly should be changed, I'd be happy.

Thanks,

M.J. Taylor
(And no, I didn't write the original code...)

PS: As an aside from my questions, and mostly for anyone stumbling on this thread, the Form Updater on lullabot.com http://www.lullabot.com/formupdater is a very useful tool. A couple of notes are in order though, when it mentions you will have to wrangle with fieldsets, it's not kidding. The field set element should be placed at the top of your grouping, and there needs to be a rolling Form tagging as you go. An Example:

Version 4.6.x

foreach(range(1,200) as $channel) {

$output .= '

Adsense '
. 'ID '"> & Readable Name #' . $channel . '' .
'

Q: Create page from module?

Say I have a node called "mynode". I want to display the content created from the node accross multiple pages. For instance:

www.url.com/mynode

would also have the pages

www.url.com/mynode/images
www.url.com/mynode/summary
www.url.com/mynode/extra

Does anybody know how I could achieve something like this?

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions