473,671 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 5836
Dormilich
8,658 Recognized Expert Moderator Expert
note as this might be due to a misunderstandin g: 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 Recognized Expert Moderator Expert
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
8083
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 that if there is default value reset and clear will become different. My understanding is that reset means to restore the original page before
5
5894
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 button to open the "file browse" dialog and the Submit button to submit the form data.
4
10982
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 happens or how I can work around this? Thanks
1
14339
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 button on my ASP.NET web page, and have an HTML reset button click clear 1) all validator text display and 2) validation summary display. Problem was clearing them and yet still leaving them working and visible if the user immediately began...
7
14615
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") = Null %>
3
18741
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' name='save_links' id='save_links'> <table cellpadding='5'>
1
1656
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 have tried to learn ASP at www.w3schools.com/asp and I cant seem to figure it out. I know there is a easier way to set it up. Please can anyone point me the way to do this or if someone can just contact through my e-mail, ObsidianMilenko@Gmail.com,...
1
1661
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 fresh page. But this is wrking fine in mozil anot not in IE Here is the snippet of code <form name="feg_dist_request_form" method="post" action="$thisurl">
1
2414
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 javascriptlint.com/ online_lint.php and a few warnings popped up, but I'm not sure if these warnings amount to much. Here's the code for the submit button: <input type="submit" name="next" class="btn" onclick="saveButtonClicked(name, 'VehicleButton');"...
0
8476
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4225
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.