Use these lines at proper places.
If the end user enters the case number in the form then it will not create a new case but searches and displays the case the user entered and the related contact based in email id.
If the end user doesn't enter the case number then it will automatically create the case and attaches to the contact.
<form method="post" id="prechatForm">
<!-- Detail inputs -->
First Name: <input type="text" name="liveagent.prechat:contactFirstName" /><br />
Last Name: <input type="text" name="liveagent.prechat:contactLastName" /><br />
Email: <input type="text" name="liveagent.prechat:contactEmail" /><br />
Case Number: <input type="text" name="liveagent.prechat:caseNumber" /><br />
Subject: <input type="text" name="liveagent.prechat:caseSubject" /><br />
<!-- Map the detail inputs to the Contact fields -->
<input type="hidden" name="liveagent.prechat.findorcreate.map:Contact" value="FirstName,contactFirstName;LastName,contactLastName;Email,contactEmail;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin;Subject,caseSubject;CaseNumber,caseNumber;" />
<!--<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="CaseNumber,caseNumber;" />-->
<!-- Try to find the Contact by email (exact match) -->
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact" value="Email,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact" value="Email,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Case" value="CaseNumber,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Case" value="CaseNumber,true;" />
<!-- If the Contact is not found, then create one with the following fields set -->
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact" value="FirstName,true;LastName,true;Email,true;" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;Subject,true;" />
<!-- Save the Contact on the Live Chat Transcript's Contact Loookup -->
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact" value="Contact" />
<!-- Show the Contact when it is found or created -->
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true" />
<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" />
<!-- Create a Case every time -->
<input type="hidden" name="liveagent.prechat:caseOrigin" value="Chat" />
<!--<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin;Subject,caseSubject;CaseNumber,caseNumber;" />-->
<!--<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;Subject,true;CaseNumber,true" />-->
<input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="Case" />
<!--<input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" />-->
<input type="hidden" name="liveagent.prechat.save:Case" value="Case" />
<!-- <input type="hidden" name="liveagent.prechat.save:Case" value="Case" /> -->
<!-- Link the Contact to the Case -->
<input type= "hidden" name="liveagent.prechat.findorcreate.linkToEntity:Contact" value="Case,ContactId;" />
<input type="submit" value="Request Chat" id="prechatForm" />
</form>