duanju9104 2010-12-19 17:31
浏览 45
已采纳

如何阻止用户将此表单空白?

I want to make one form don't do anything at all if what is submitted in the first field is shorter than 5 characters.

I got a code for a similar thing but it doesn't work on this form since the second field is hidden and it's filled by the page, so the form isn't blank when submitted.

So I want the form not do anything if when submitted what's typed on the first field is under 5 characters.

This is the form:

<form class="questionform" name="questionform-0" id="questionform-0">

<textarea class="question-box" style="width:97%;" cols="20" rows="4"  id="question-box-' . $questionformid . '" name="title" onfocus="if(this.value == \'\'){this.value = \'\';}" onblur="if(this.value == \'\'){this.value = \'\';}"></textarea>

<input type="hidden" class="ubicacion" style="width:60%; font-weight:bold; border-color:white; background:white; color:white" value="<?php the_search_query(); ?> " name="question" /></p>

<div class="question-form-bottom"><input type="button" name="ask" value="Publicar" onclick="askquestion('questionform-0');"></div></form>

If it's not clear or you need more info please ask. Thanks

  • 写回答

3条回答 默认 最新

  • dqdjfb2325 2010-12-19 17:35
    关注

    You really can't stop someone from doing it. You could try a JavaScript check but also someone might disable it and submit anyway. Best method is always do server side validation and just return an error like you js check would do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)