force search!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

force search!

Post by sirTemplar »

i have a form to search my database. what do i have to put to force those who search to fill-in at least one search field? because right now, when someone clicks on seach without anything, it will bring out all the data on the database :( , please help!
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

I recommend using something like JavaScript to validate the input. Change the button type (in HTML) from submit to button where it call a function to validate the data in the form when the user clicks on it.

Example:

Code: Select all

<input type="button" value="Continue ->" onClick="validate_form(this.form)">

// Function to validate the input of the form
<script>
    function validate_form(form)
    &#123;
          
        if ( form.s_type.options&#1111;form.s_type.selectedIndex].text=="")
        &#123;
            alert("You must select a unit type");
            form.s_type.focus();
            return false;
        &#125;
        
        if ( form.s_base_type.options&#1111;form.s_base_type.selectedIndex].text=="")
        &#123;
            alert("You must select a base type");
            form.s_base_type.focus();
            return false;
        &#125;
	
	form.submit();
    &#125;

</script>
You will obviously need to modify the code for your own use but that should get you started.

John M
Post Reply