473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation Error for feedback Text area

1 New Member
Heyy guys, Im a total newbie to php and have begun learning it.
I was creating a Php form for name and feedback in which I have put some validation conditions for name and feedback,like if they are empty it should display empty.But somehow its only displaying it for name and not for feedback.Can you please find any mistake in my code so that I can proceed further.Thanks for the help.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <style>
  4. .error {color: #FF0000;}
  5. </style>
  6. </head>
  7. <body>
  8. <?php
  9. // define variables and set to empty values
  10. $nameErr = $feedbackErr= "";
  11. $name = $feedback= "";
  12.  
  13. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  14.   if (empty($_POST["name"])) {
  15.     $nameErr = "Name is required";
  16.   } else {
  17.     $name = test_input($_POST["name"]);
  18. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  19.   $nameErr = "Only letters and white space allowed"; 
  20. }  
  21.   }
  22.  
  23.   if (empty($_POST['feedback'])) {
  24.     $feedbackErr = "Feedback is required";
  25.   } else {
  26.     $feedback= test_input($_POST["feedback"]);
  27.   }
  28.  }
  29.  
  30. function test_input($data) {
  31.   $data = trim($data);
  32.   $data = stripslashes($data);
  33.   $data = htmlspecialchars($data);
  34.   return $data;
  35. }
  36. ?>
  37. <p><span class="error">* required field.</span></p>
  38. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
  39. <fieldset>
  40. Name:<br>
  41. <input type="text" size="20" name="name" value="<?php echo "$name"; ?>">
  42. <span class="error">* <?php echo $nameErr;?></span>
  43.  <br><br>
  44. Feedback:<br>
  45. <textarea name='feedback' rows="4" cols="20">    
  46. </textarea>
  47. <span class="error">* <?php echo $feedbackErr;?></span>
  48.   <br><br>
  49. <input type="submit" value="Email This Form" id="but">
  50. </fieldset>
  51. </form>
  52.  
  53.  
  54. </body>
  55. </html>
Jun 23 '16 #1
1 1315
Dormilich
8,658 Recognized Expert Moderator Expert
your textarea contains a line break, which doesn’t count as empty.

second, do away with the test_input() function. it creates context changes where no context change exists. and its name is also misleading.
Jun 24 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3789
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens provide text area where the user can insert big chunks of text and submit it all to the server paragraph by paragraph. The requirement is to do a...
1
3958
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException : Validation error: The element 'http://xmlns.somewhere.com/something:rDetail' cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'. An...
1
2565
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException : Validation error: The element 'http://xmlns.somewhere.com/something:rDetail' cannot contain text. Expected 'http://xmlns.somewhere.com/something:AList'. An...
4
1665
by: Vikas Kumar | last post by:
propertyDescription += "<br>" + lblpropertyDescription.Text; //here i am reading some text from text area i test wrting "p" in my text area it wrks fine but when i write <pin my text area it gives the following error Error Message:A potentially dangerous Request.Form value was detected from the client (lblpropertyDescription="...
1
2315
by: divya | last post by:
I have a form which has a textarea,name - txtTo where he adds email addresses.Now when he clicks on sendemail I want to open a mailto link with addresses taken from textarea. Example I added in the text area these three addresses divyasanam@yahoo.com,ewew@yah.com,gjh@yahoo.com and now when I click on send email a ComposeMail window in...
8
2146
by: leslietulip | last post by:
Greetings - this is the first time I am posting to this forum. I am using Javascript to ensure that the user enters all required fields in a form. However, this form is being spammed to death with the user or a robot filling up all fields and sending tons of html links in the text area of a comments/question box. I want to use javascript to see if...
5
7045
by: SSG | last post by:
I have text area having 4 rows & 10 cols.. while I am typing in Textarea , it should not accept the 5 th row & 11 th col... Hw to create text area like that....
1
1949
by: truptidalia | last post by:
Hello, I am trying to add 2 RadioButtons in a form in js dynamically. I can see 2 radiobutttons, but no text. On clicking them, their is no selection. One of them is selected. I need to retrive their vakue on button click. The form is added in a div which is present in html form (that is not dynamically created). Form & all other elements...
4
2735
by: Badboy112 | last post by:
Hi guys i have used a data file like you guys have asked me to but im not entirely sure how to use the DataInputStream What i would like to do for this assigment is import the text from the data file and keep that text in the specific text area even after i closed it and then i would like to hold that same text in the text Area after i have...
1
3811
by: simon2x1 | last post by:
I use the NicEdit(www.nicedit.com) text-editor on my Text Area which is working and the below code to hide and show text area after selecting a value in the drop down it will show the text area but this is what i need help with: 1) i want the text area to show even before you select any value from the drop down. 2) i want the Text...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.