Tags:
create new tag
view all tags

Question

I have a construct like this to put up a create box for a form:

New topic name

It works great except if you leave the input box blank and press "Create" you get sent to the %MAKETEXT edit screen. How do I force a not empty text entry?

The literal code is:

<form name="TestTopic5" action="%SCRIPTURLPATH{"edit"}%/%WEB%/"> <input type="hidden" name="formtemplate" value="TestTopic4" > New topic name <input type="text" name="topic",  size="40" /> <input type="submit" class="twikiSubmit" value="Create" /> </form> 

Environment

TWiki version: TWikiRelease04x02x00
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser: Fox
Categories: Forms

-- JohnGee - 03 Jun 2008

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

The following code shows how you can use a bit of javascript to both make sure the topic name field is not empty and also call upon some of TWiki's core javascript to clean up what is entered in the field.

<script type="text/javascript">
//<![CDATA[

function submitForm(form) {
  if (form.topic.value == "") {
         alert("Please enter topic name.");
         return false;
   }
   return true;
}
//]]>
</script>

<form name="myTestForm" action="%SCRIPTURLPATH{"edit"}%/%WEB%/" onsubmit="return submitForm(this);" > New topic name <input type="text" name="topic",  size="40" onblur="document.myTestForm.topic.value=removeSpacesAndPunctuation(capitalize(this.value));" /> <input type="submit" class="twikiSubmit" value="Create" /> </form> 

-- LynnwoodBrown - 03 Jun 2008

Change status to:
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2008-06-03 - LynnwoodBrown
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.