PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Default value of query field in custom form not displaying

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Default value of query field in custom form not displaying

    Hi there,

    I have created a custom form and it works fine.

    The only problem is that the query field does not re-populate based on the previous search.

    Here's my field -

    Code:
    <input id="query" name="zoom_query" value="" class="zoom_searchbox" type="text">
    How can I get the query field to populate with the previous search?

    Do I need to add anything to the 'value' attribute of the field?

  • #2
    Please see previous threads such as these:
    http://www.wrensoft.com/forum/showthread.php?t=2112
    http://www.wrensoft.com/forum/showthread.php?t=802
    http://www.wrensoft.com/forum/showthread.php?t=906

    Note that you should verify whether you really need to define a custom search form if it is important to you that the fields are re-populated.

    You can customize the generated search form (which does automatically re-populate the fields) via CSS (see this FAQ, scroll down for an example) and the Advanced Template Options (see chapter 6.7 of the Users Guide) which allows you to rearrange the order and position of the search form elements.
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      Just remembered this is the V5 forum (I presume you are actually using V5). The aforementioned "Advanced Template Options" are only available in V6. Take a look at what it offers and see if you need the upgrade.
      --Ray
      Wrensoft Web Software
      Sydney, Australia
      Zoom Search Engine

      Comment


      • #4
        Hi Ray
        Thanks for pointing out the posts.
        I have done what Taluswood did on post http://www.wrensoft.com/forum/showthread.php?t=2112
        I created a javascript function/object to get the querystring, then parse it and then insert it into the value of the main search box.

        For anyone who is interested, here's the javascript -
        Code:
        function Querystring(qs) { // optionally pass a querystring to parse
        	this.params = {};
        	
        	if (qs == null) qs = location.search.substring(1, location.search.length);
        	if (qs.length == 0) return;
        
        // Turn <plus> back to <space>
        // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
        	qs = qs.replace(/\+/g, ' ');
        	var args = qs.split('&'); // parse out name/value pairs separated via &
        	
        // split out each name=value pair
        	for (var i = 0; i < args.length; i++) {
        		var pair = args[i].split('=');
        		var name = decodeURIComponent(pair[0]);
        		
        		var value = (pair.length==2)
        			? decodeURIComponent(pair[1])
        			: name;
        		
        		this.params[name] = value;
        	}
        }
        
        Querystring.prototype.get = function(key, default_) {
        	var value = this.params[key];
        	return (value != null) ? value : default_;
        }
        
        Querystring.prototype.contains = function(key) {
        	var value = this.params[key];
        	return (value != null);
        }
        var qs = new Querystring();
        And you'll also have to execute this code after the zoom_query form field is rendered to the page -
        Code:
        			<input id="query" name="zoom_query" value="" class="zoom_searchbox" type="text">
        			<script  language="javascript">
        				document.getElementById('query').value = qs.get('zoom_query','Enter Search Phrase Here');
        			</script>

        Comment

        Working...
        X