Question
I have a construct like this to put up a create box for a form:
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
--
JohnGee - 03 Jun 2008
Answer
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