- Moderated by:
- Support
-
- rank:
-
Helper
- registered:
- July 2003
- Status:
- offline
- last visit:
- 11.04.06
- Posts:
- 261
Hi,
I am trying to learn to write modules. I have a good start, but I'm trying to add a search box. I studied the search block and search module, but still can't figure this thing out.
This is my code snippet:
Code
$content = "<form method=\"post\" action=\"modules.php?op=modload&name=testmodule&file=index&mode=search&query=\">";
$content .= "<center><input type=\"text\" name=\"query\" size=\"14\">";
$content .= '<input type="submit" value="Search">';
$content .= '</center>';
$content .= '</form>';
echo $content;
What I want is the search term to appear at the end of the url:
modules.php?op=modload&name=testmodule&file=index&mode=search&query=
line such as:
modules.php?op=modload&name=testmodule&file=index&mode=search&query=dog
Right now when I click on the search button, the page goes to modules.php?op=modload&name=testmodule&file=index&mode=search&query=
I can't get it to append the search term to the end of that line.
Can anyone help me out on this?
Thanks,
Grant
--
Retail Retreat
http://www.retailretreat.com -
- rank:
-
Helper
- registered:
- July 2003
- Status:
- offline
- last visit:
- 11.04.06
- Posts:
- 261
OK, a bit of web surfing lead me to using
Code
global $HTTP_POST_VARS;
to get the post data. I'd still like to know how to append it to the end of the URL above, if someone can help me with that.
Thanks,
Grant
--
Retail Retreat
http://www.retailretreat.com -
- rank:
-
Helper
- registered:
- July 2003
- Status:
- offline
- last visit:
- 11.04.06
- Posts:
- 261
I may be getting closer...
I changed the code to:
Code
$content = "<form method=\"GET\" action=\"modules.php?\">";
$content .= "<center><input type=\"text\" name=\"op=modload&name=hotdeals&file=index&mode=search&query\" size=\"14\">";
$content .= '<input type="submit" value="Search">';
$content .= '</center>';
$content .= '</form>';
and now when I search, the search term is appended, so it looks like this in my browser:
modules.php?op%3Dmodload%26name%3Dtestmodule%26file%3Dindex%26mode%3Dsearch%26query=test
I guess the = and &'s are escaped out.
Anyways, now I'm getting an error that says:
Sorry, you can't access this file directly...
If I hand-edit the URL and change the %3D's to = and %26's to &, then the URL seems to work like I want it to. I'm not sure how to keep the characters from escaping though. I guess PostNuke doesn't like that.
I feel like I'm getting close, but any help would be much appreciated.
Thanks,
Grant
--
Retail Retreat
http://www.retailretreat.com -
- rank:
-
Helper
- registered:
- January 2004
- Status:
- offline
- last visit:
- 22.02.08
- Posts:
- 381
Don't use:
Code
$content .= "<center><input type=\"text\" name=\"op=modload&name=hotdeals&file=index&mode=search&query\" size=\"14\">";
I question whether that would ever work.
Try this:
Code
$content = "<form method=\"get\" action=\"modules.php?op=modload&name=testmodule&file=index&mode=search\">";
$content .= "<center><input type=\"text\" name=\"query\" size=\"14\">";
$content .= '<input type="submit" value="Search">';
$content .= '</center>';
$content .= '</form>';
echo $content;
Or another way:
Code
$content = "<form method=\"get\" action=\"modules.php\">";
$content .= "<input type=\"hidden\" name=\"op\" value=\"modload\">";
$content .= "<input type=\"hidden\" name=\"name\" value=\"testmodule\">";
$content .= "<input type=\"hidden\" name=\"file\" value=\"index\">";
$content .= "<input type=\"hidden\" name=\"mode\" value=\"search\">";
$content .= "<center><input type=\"text\" name=\"query\" size=\"14\">";
$content .= '<input type="submit" value="Search">';
$content .= '</center>';
$content .= '</form>';
echo $content;
Keep in mind that NONE of this is pnAPI compliant.
-Chris -
- rank:
-
Helper
- registered:
- January 2004
- Status:
- offline
- last visit:
- 22.02.08
- Posts:
- 381
It's just as easy to set the action to be "index.php?module=testmodule&func=search" and then have your pnuser.php file include the function testmodule_user_search() and then make sure to get all your arguments using pnVarCleanFromInput(). And use either pnHTML or pnRender to return your output.
If you are writing a search plugin for the existing search module then you can still use the pnRender or pnHTML method in your search_testmodule_opt() and search_testmodule() functions in your includes/search/testmodule.php file. You don't even need to have all the code in the search_testmodule() function. Just load the API for your module and call pnModFunc('testmodule','user','search'); and then have all the search code located in your pnuser.php and pnuserapi.php files in the testmodule_user_search and testmodule_userapi_search() functions. Just return the final result back to the search_testmodule() function inside includes/search/testmodule.php.
I don't see why this couldn't be 100% API compliant.
-Chris -
- rank:
-
Helper
- registered:
- July 2003
- Status:
- offline
- last visit:
- 11.04.06
- Posts:
- 261
R3ap3r,
Thank you for your help. You second example worked fine. I tried the first suggestion, but it kept sending me to
modules.php?query=something.
It didn't seem to want to add the op=modload&name=testmodule&file=index&mode=search after modules.php. Maybe it's the question mark messing it up?
Thanks,
Grant
--
Retail Retreat
http://www.retailretreat.com
