[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I make a required field for the text area?

Posted on 2004-10-22
15
Medium Priority
?
224 Views
Last Modified: 2013-12-24
I know in ColdFusion I can just write text fields like this to make them required.

<cfinput type="text" name="subject" required="yes" message="Please Enter The Subject Of Your News.">


But how do I make a textarea act the same way?
0
Comment
Question by:fixx17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
15 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 12382048
It is really just done through javascript - so really someone could turn off javascript and submit your enite form blank or with invalid data.

You should be sure to use server side checking as well.

When you do that it looks like this:
<cfset ErrorList = "">

<!--- Radio Button --->
<cfif NOT IsDefined("Form.radioname")>
<cfset ErrorList = "Please select a choice from the radio button">
</cfif>

<!--- textbox/area --->
<cfif Len(Form.inputname) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
</cfif>


0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12382694
Hi fixx17,
you can not use cfinput to work with the text area.
you can refer this web site for javascript text area validation
http://www.javascriptkit.com/javatutors/form6.shtml

Regards,
---Pinal
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12382839
Hi fixx17,
<form name="feedback" action="script.cgi" method="post" onSubmit="return checkform()">
<input type="text" name="name">
<input type="text" name="email">
<textarea name="comments"></textarea>
</form>

if (document.feedback.field.value == '') {
    return false;
}


http://www.yourhtmlsource.com/javascript/formvalidation.html


Regards,
---Pinal
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 1

Author Comment

by:fixx17
ID: 12382888
Ok , mrichmon

I've tried to use this.

<!--- textbox/area --->
<cfif Len(Form.inputname) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
</cfif>


I am not sure if I am suppose to use EQ 0

I used your code like this

<!--- textbox/area --->
<cfif Len(Form.news) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
</cfif>

But I get an error that says "Error with ELEMENT News"

I am using a textarea for people to insert news to the front page for our website.  The code <cfif Len(Form.news) EQ 0> looks like it's looking for a number, not text.

pinaldave

I see the javascirpt on the link you sent, but it explains how to do it if a parameter is missing.  Such as the "@" symbol for e-mails.  But it does not show how to check if anything is missing.  Sorry, I am not a java expert.

This is what I have right now.
<cfform name="form1" method="post" action="postto1.cfm">
      
      <table width="100%"  border="0">
        <tr>
          <td colspan="4"><span class="style14">Post News, Events and Updates </span></td>
        </tr>
        <tr>
          <td width="14%">&nbsp;</td>
          <td width="13%">&nbsp;</td>
          <td width="44%">&nbsp;</td>
          <td width="29%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" valign="top"><span class="style17">Name</span><span class="style18">:</span></td>
          <td><cfinput type="text" name="name" required="yes" message="Please Enter Your Name"></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" valign="top"><span class="style17">Subject</span></td>
          <td>
            <cfinput type="text" name="subject" required="yes" message="Please Enter The Subject Of Your News.">
          </td>
          <td></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" valign="top"><span class="style17">News</span></td>
          <td><textarea name="news" cols="60" rows="10"></textarea></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit" value="Submit"></td>
          <td>&nbsp;</td>
        </tr>
      </table></cfform>


Any suggestions.


0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12382920
Do this...

<cfif isdefined('form.news') and Len(Form.news) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
</cfif>

it should do the trick!
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12382940
the reason is says it is undefined as you have not submitted the form yet... that is why...
the other method is you define that as default param like
<cfparam name="form.news" default="" type="string">

but that will not do the trick in your case as you want to validate that and if you keep it null it will always show up... also that is bad practice to declare as form.news  so use the previous method...
---Pinal
0
 
LVL 1

Author Comment

by:fixx17
ID: 12383095
Pinal

I've tried this.

<script>
function checkform()
{
      if (document.form.news.value == ' ') {
      return false;
}

</script>

<cfform name="form1" method="post" action="postto1.cfm" onSubmit="return checkform()">

It still will pass no information to the database and nothing gets posted from the text area.


I also tried this

<cfif isdefined('form.news') and Len(Form.news) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
</cfif>

This still passed over to the database with nothing into the new field.  I can get subject, name to work, but not news.

Am I missing something?
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12383120
Hi fixx17,
========================================================
page 1
your form
========================================================
page 2
<cfif isdefined('form.news') and Len(Form.news) EQ 0>
<cfset ErrorList = "Please fill out the textbox/textarea">
<cfelse>
your database operation of insert/update
</cfif>
========================================================

Regards,
---Pinal
0
 
LVL 1

Author Comment

by:fixx17
ID: 12383227
Pinal,

I've tried it just as you posted.  But for some reason, it still passes through with nothing being inputed into the textarea field.

========================================================
page 1 = postnews.cfm


<cfform name="form" method="post" action="postto1.cfm">
<cfinput type="text" name="name" required="yes" message="Please Enter Your Name">
<cfinput type="text" name="subject" required="yes" message="Please Enter The Subject Of Your News.">
<textarea name="news" cols="60" rows="10"></textarea>
<input type="submit" name="Submit" value="Submit">
========================================================
page 2= postto1.cfm
<cfif isdefined('form.news') and Len(Form.news) EQ 0>
<cfset ErrorList = "Please fill out the textarea">
<cfelse>

<cfquery name="postit" DATASOURCE="news">
  insert into teamnews
  (name,
   subject,
   news )
   values
      ('#form.name#',
       '#form.subject#',
       '#form.news#')

</cfquery>
</cfif>
========================================================


It still does the same thing.  It will pass and nothing gets inputed into the database.  
I just want it to catch if the user forgets to input stuff into the field.

Thanks for tyring.  I will keep plugging away.
0
 
LVL 21

Accepted Solution

by:
pinaldave earned 1200 total points
ID: 12383312
let us try again....
========================================================
page 1 = postnews.cfm


<cfform name="form" method="post" action="postto1.cfm">
<cfinput type="text" name="name" required="yes" message="Please Enter Your Name">
<cfinput type="text" name="subject" required="yes" message="Please Enter The Subject Of Your News.">
<textarea name="news" cols="60" rows="10"></textarea>
<input type="submit" name="Submit" value="Submit">
========================================================
page 2= postto1.cfm
<cfif isdefined('form.news') and (Len(Form.news) EQ 0 or form.news eq '')>
<cfset ErrorList = "Please fill out the textarea">
<cfelse>

<cfquery name="postit" DATASOURCE="news">
  insert into teamnews
  (name,
   subject,
   news )
   values
     ('#form.name#',
      '#form.subject#',
      '#form.news#')

</cfquery>
</cfif>
========================================================
0
 
LVL 1

Author Comment

by:fixx17
ID: 12383360
Bingo!

This seemed to stop it from inputing with an empty textarea.  Thank you,

BUT now it just shows a blank page.  Is there anyway to setup an alert it tells the user they did not do?

Right now it just shows a blank white page.
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12383373
Hi fixx17,
<cfif isdefined('form.news') and (Len(Form.news) EQ 0 or form.news eq '')>
<cfset ErrorList = "Please fill out the textarea">
<cfoutput>#ErrorList#<br>Also you can link anything here or type...</cfoutput>
<cfelse>


Regards,
---Pinal
0
 
LVL 1

Author Comment

by:fixx17
ID: 12383458
Thanks, I understand more what you did.  

But I think I need to disect this area of the code and understand what is going on.

<cfif isdefined('form.news') and (Len(Form.news) EQ 0 or form.news eq '')>

I will award the points to you.

Thank you.
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12383478
Hi fixx17,
<cfif isdefined('form.news') -------->>> means if the form.news param is there or not... if it is there... then it is fine... if not then do not proceed


and (Len(Form.news) EQ 0 -------->>> if the lenth is more 0 means it is there... then only....

OROROR

or form.news eq '')-------->>> if it is null...



>


Regards,
---Pinal
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 12383482
Hi fixx17,
it is fun to help as I learn also...
Regards,
---Pinal
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question