We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16892
    • 107 Posts
    I came across this modded version of FlexSearchForm and the thread ended pretty much with this question.

    Quote from: rodsor at Jul 12, 2006, 06:15 AM

    Thanks guys. Now I can view the snippet (only the txt). But after changing the snippet code, the following error ocurrs:

    Fatal error: Cannot redeclare preparesearchcontent() (previously declared in C:\Apache2\htdocs\manager\includes\document.parser.class.inc.php(705) : eval()’d code:466) in C:\Apache2\htdocs\manager\includes\document.parser.class.inc.php(705) : eval()’d code on line 475

    How to correct this?


    Whoever did the last mod, added two functions to the end of the script, after the return command. I moved the functions to their proper place and the snippet started working.

    This seems to be the latest (modded) version of FlexSearchForm.

    // -----------------------
    // Snippet: FlexSearchForm
    // -----------------------
    // Version: 0.6j
    // Date: 2005.02.01
    // [email protected]
    //
    // This snippet was designed to create a search form
    // that is highly flexible in how it is presented. It
    // can be used as both a small, subtle, persistent
    // search field element, as well as present the search
    // results. All elements are branded with classes
    // for easy CSS styling.
    // 
    // 2006.02.06 added extract functionality by Marc Hinse, [email protected]
    // some extract functionality credits go to Joomla Open Source CMS
    
    // 2006.05.01 Modified by Stephan Dale for http://mindSpill.net. Email: modx(a)mindspill.net
    // Added access control, i.e. hide private documents if the user doesn't have permission to view them. This functionality uses code lifted from the MODx getDocumentObject method in document.parser.class.inc.php.
    // Added better support for weblinks.
    // &useWeblink - [ true | false ] If true and the doc is of type 'reference', link to the doc's weblink (it's 'content' field) rather than to the doc itself. Defaults to false.
    // &weblinkClass - [ string ] CSS class for a weblink's anchor. Defaults to "weblink".
    


    Access control is working; I haven’t tried weblinks. Apologies if this is the current version of the snippet and I didn’t know it.
      • 867
      • 241 Posts
      Someone knows ?

      huh
        • 16892
        • 107 Posts
        Knows what? I’m using the file above on my site with no problem.
          • 19986
          • 90 Posts
          Even though it’s marked as fixed, I thought I’d update this topic because a solution wasn’t presented (and I have a vested interest given that I made the mods mentioned and I’ve just hit the problem myself!).

          The "cannot redeclare" problem arises when a snippet declares a function and is used twice in a template. A good example of this is the FlexSearchForm snippet because it can be used on a page to display both a search box and the search results. It seems that some PHP configurations generate the "cannot redeclare" error and others don’t. I was not having this problem until I recently migrated to a new server.

          The solution is to check whether the function exists before declaring it. So, for every function, surround it with a function_exists call, like so:

          if (!function_exists('TheFunction')) {
              function TheFunction {
              ...
              }
          }
            • 16892
            • 107 Posts
            step, are you saying the file i attached to the original message is still wrong?

            thanks.
              • 19986
              • 90 Posts
              I have no idea what your version changed, so no.

              Briefly looking at it, it’s possible that a problem would still arise if referencing the snippet twice on a page, because the function declarations are not surrounded with checks to see if the functions exist already (as per my previous post).

              What does your version add?
                • 19986
                • 90 Posts
                Oh, I see what you did. You moved the function inside a conditional. That could do the trick, though I’m not sure about the intricacies of php.