473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

reset button not function but submit button can use.anybody can help

Expand|Select|Wrap|Line Numbers
  1. <html> <head> <style>
  2. .error {color: #FF0000;}
  3. </style> </head> <body> <?php
  4.  
  5. $nameErr = $emailErr = $genderErr = $websiteErr = $nokpErr = "";
  6. $name = $email = $gender = $nokp = $website = "";
  7.  
  8. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  9.    if (empty($_POST["name"])) {
  10.      $nameErr = "Name is required";
  11.    } else {
  12.      $name = test_input($_POST["name"]);
  13.      // check if name only contains letters and whitespace
  14.      if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  15.        $nameErr = "Only letters and white space allowed";
  16.      }
  17.    }
  18.  
  19.    if (empty($_POST["email"])) {
  20.      $emailErr = "Email is required";
  21.    } else {
  22.      $email = test_input($_POST["email"]);
  23.      // check if e-mail address is well-formed
  24.      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  25.        $emailErr = "Invalid email format";
  26.      }
  27.    }
  28.  
  29.    if (empty($_POST["website"])) {
  30.      $website = "";
  31.    } else {
  32.      $website = test_input($_POST["website"]);
  33.      if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
  34.        $websiteErr = "Invalid URL";
  35.      }
  36.    }
  37.  
  38.    if (empty($_POST["nokp"])) {
  39.      $nokpErr = "";
  40.    } else {
  41.      $nokp = test_input($_POST["nokp"]);
  42.      if (!preg_match("/^[1-9][0-9]{0-17}$/",$nokp)) {
  43.        $nokpErr = "Only number is allowed";
  44.    }}
  45.  
  46.    if (empty($_POST["gender"])) {
  47.      $genderErr = "Gender is required";
  48.    } else {
  49.      $gender = test_input($_POST["gender"]);
  50.    }
  51. }
  52.  
  53. function test_input($data) {
  54.    $data = trim($data);
  55.    $data = stripslashes($data);
  56.    $data = htmlspecialchars($data);
  57.    return $data;
  58. }
  59. ?> <h2>PHP Form</h2> <p><span class="error">* required field.</span></p> <form method="post" action="https://bytes.com/<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> <p>Name:
  60.   <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> </p> <p>No KP:
  61.      <input name="nokp" type="text" id="nokp" value="<?php echo $nokp;?>" size="12"> <span class="error">* <?php echo $nokpErr;?></span></p> <p>
  62.      E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br>
  63.      Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span><br><br>
  64.      Gender:
  65.      <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?>  value="male">Male
  66.      <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?>  value="female">Female
  67.      <span class="error">* <?php echo $genderErr;?></span> <br><br> <button type="submit" value="Submit">Submit</button> <button type="reset" value="Reset">Reset</button> </p> </form> <?php
  68.  
  69. echo "<h2>Your Input:</h2>";
  70. echo $name;
  71. echo "<br>";
  72. echo $nokp;
  73. echo "<br>";
  74. echo $email;
  75. echo "<br>";
  76. echo $website;
  77. echo "<br>";
  78. echo $gender;
  79.  
  80. ?> </body> </html>
Feb 15 '16 #1
2 5833
Dormilich
8,658 Expert Mod 8TB
note as this might be due to a misunderstanding: a reset button does not empty a form. it undoes any changes made to the form values applied after loading the form.
Feb 16 '16 #2
Dormilich
8,658 Expert Mod 8TB
moved to HTML as this is not a PHP issue.
Feb 16 '16 #3

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

Similar topics

2
by: Matt | last post by:
i need to implement a clear button to clear all the fields in the form, but i am thinking i can just use reset button. <input type="reset" name="reset" value="CLEAR"> The first thought is...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
4
by: Chris Lane | last post by:
Hi, I have an HTML RESET button and Web Control Button that posts back to the server. Problem is the reset button doesn't work after the postback occurs. Any ideas or suggestions as to why this...
1
by: NancyASAP | last post by:
Thought I'd share this since it took me a long time to get it working. Thanks to a bunch of contributers in Google Groups who shared javascript, etc. The question was: How can I put a reset...
7
by: Kermit Piper | last post by:
Hello, How can you clear session variables when a reset button is pressed? I thought I might be able to do something like: <% If request.form("Reset") = "Reset" then Session("variable") =...
3
by: kashif_khan | last post by:
hi everyone, can anybody please tell me why reset button is not working in the following code, i tested it in opera, firefox and konqueror, <form action='edit_links.php' method='POST'...
1
by: Areith | last post by:
Hello, I have been looking all around on how to set the Submit button just give a conformation that the form was submited and have the form be sent straight to my domain so I can check the results. I...
1
by: anthriksh200 | last post by:
Hello, I have perl -cgi script in which we have used the javascript . In this the " resret" button is there which should reset the form defaut values (interms of drop down and then reload the ...
1
by: partlocator | last post by:
I'm checking on some code my developer did for a form on our site. The code relates to a submit button and I'm not sure if it's functioning properly. I ran the javascript through...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.