-3
<html>
<head>
<title>Form Sheet</title>

<style>

</style>
<script type="text/javascript">

</script>

</head>

<body>

</body>

<form name="formsheet" action="grade.php" method="post">

<table width="300" border="5">
<tr>
<td>FirstName:</td> 
<td><input type="text" id="fname" name="fname"/></td>

<tr>
<td>SurName:</td>
<td><input type="text" id="sname" name="sname"/></td>
</tr>
<tr>
<td>Age:</td> 
<td><input type="text" id="age" name="age"/></td>
</tr>
<tr>
<td><input type="radio" id="gen" name="gen" value="Male"/>Male
<input type="radio" id="gen" name="gen" value="Female"/>Female</td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" id="subject" name="subject"/></td>
</tr>
<tr>
<td>Score:</td>
<td><input type="number" id="score" name="score"/></td>
</tr>
</table>
<input type="reset"name="reset"/>
<input type="submit" id="sbm" name="sbm" value="submit"/>
<p><h3>would you like to go to the Home page?<a href="homepage.html">click here</a></h3></p>

</form>

</body>
</html>

need to validate this for but i dont know the codes and how to do so plz help would truly appreciate it

Edited by pritaeas: Fixed markdown.

6
Contributors
14
Replies
81
Views
4 Years
Discussion Span
Last Post by Zagga
Featured Replies
  • 1
    diafol 3,669   4 Years Ago

    Why have you started a new thread on this? This is surely an extension of your question: http://www.daniweb.com/web-development/php/threads/459031/need-help-urgently-need-to-validate-this-form-to-grade.php-idk-how If you search for 'php form validation', 'form processing php' or anything like that, you'll get a lot of useeful hits. Also '$_POST php'. >but i dont know the codes >plz help … Read More

1

First of all read the rules. Nothing is urgent. Secondly, what do you wish to validate? That surname is just characters, age is just digits, that all fields have more than 2 characters? Need more information.

0

You can validate the form client side using javascript. What exactly are you trying to validate... Form filled, specific range of values, etc..????

0

i am tryin to validate the form field so if the input is not correct say numbers in the name field i would get an error message and if ever field is ok it will be successful and go to the processing page btw i am new to programming

1

Why have you started a new thread on this? This is surely an extension of your question:

http://www.daniweb.com/web-development/php/threads/459031/need-help-urgently-need-to-validate-this-form-to-grade.php-idk-how

If you search for 'php form validation', 'form processing php' or anything like that, you'll get a lot of useeful hits. Also '$_POST php'.

but i dont know the codes

plz help urgent

These types of statements will most likely see you get little help. If you show a willingness to do some initial work yourself, you'll get a lot of help. Holding out your hand with a 'gimme codez' sign probably won't work.

0

You may want to start by validating the HTML. Just glancing over the code I see you don't have a doctype declaration, which is a requirement for all valid HTML pages; you are closing the <body> tag right after you open it, before you add the form; and you've got a duplicate ID ("gen"). Also, you don't specify a charset, and while that's not a requirement as such, it's not a great idea to leave that out.

0

You may want to start by validating the HTML. Just glancing over the code I see you don't have a doctype declaration, which is a requirement for all valid HTML pages; you are closing the <body> tag right after you open it, before you add the form; and you've got a duplicate ID ("gen"). Also, you don't specify a charset, and while that's not a requirement as such, it's not a great idea to leave that out.

He was told about many of these things on the other thread, but doesn't seem to have taken any notice. Oh well...

0

O, right. I didn't read far enough down on that one. I suppose it can't hurt to repeat it. Although something tells me it's a wasted effort in this case.

0

something tells me it's a wasted effort in this case.

I hope not, we're all still here ready to help.

@keishawndavid

Show us some code that you've tried to use so that we can advise you further.

0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Form Sheet</title>
<meta name="keywords" content="JavaScript validation form, formsheet"/>
<meta name="description" content="JavaScript form validation using a formsheet."/>

<script type="text/javascript">
  function formValidation()

      {

  var fn = document.registration.fname;
  var sn = document.registration.sname;
  var num = document.registration.age;
  var umgen = document.registration.mgen;
  var ufgen = document.registration.fgen;
  var sub = document.registration.subject;
  var sco = document.registration.score;
  if(fname_validation(fn,2,10))

      {

  if(allLetter(sn))

      {

  if(allnumeric(num))



      {



  if(validgen(umgen,ufgen))



      {



  if(allLetter(sub))




      {




  if(allnumeric(sco))



      {




  }


  }


  }


  }


  }


  }
  return false;

  }

  function fname_formValidation(fn,mx,my)

  {

  var fn_len = fn.value.lenght;
  if(fn_len==0 || fn_len >= my || fn_len < mx)

  {

  alert('First name must not be empty/ length be between "+mx+" to "+my);
  fn.focus();
  return false

 }

  return true;

  }

  function allLetter(sn)

  {

  var letters=/^[A-Za-z]+$/;
  if(sn.value.match(letters))

  {

  return true;

  }

  else

  {

  alert('Surname must have alphabet characters only');
  sn.focus();
  return false;

  }

  }

  function allnumeric(num))

  {

  var numbers = /^[1-13]+$/;
  if(num.value.match(numbers))

  {

  return true;

  }

  else

  {

  alert('Age must be numeric characters only between 1-13');
  num.focus();
  return false;

  }

  }

  function validgen(umgen,ufgen)

  {

  x=0;
  if(umgen.checked)

  {

  x++;

  }

  if(ufgen.checked)

  {

  x++;

  }

  if(x==0)

  {

  alert('Select Male/Female');
  umgen.focus();
  return false;

  }

  }

  function allLetter(sub)

  {

  var letters=/^[A-Za-z]+$/;
  if(sub.value.match(letters))

  {

  return true;

  }

  else

  {

  alert('Please enter a subject');
  sub.focus();
  return false;

  }

  }

  function allnumeric(sco))

  {

  var numbers = /^[0-100]+$/;
  if(sco.value.match(numbers))

  {

  return true;

  }

  else

  {
  alert('Enter a score between 0 to 100');
  sco.focus();
  return false;
  }
  else
  {

  alert('Form Succesfully Submitted');
  window.location.reload()
  return true;

  }

  }
</script>

</head>


<body onload="document.registration.fname.focus();"></body>


<form name='registration' method="post" action="grade.php" onsubmit="return formValidation();">

       <table width="300" border="5">
       <tr>
       <td><label for="fname">FirstName:</label></td> 
       <td><input type="text"  name="fname"/></td>
       </tr>


        <tr>
        <td><label for="sname">SurName:</label></td>
        <td><input type="text"  name="sname"/></td>
        </tr>


        <tr>
        <td><label for="age">Age:</label></td> 
        <td><input type="text"  name="age"/></td>
        </tr>

        <tr>
        <td><label id="gender">Gender:</label></td><td>
        <input type="radio"  name="gen" value="Male"/><span>Male</span>
        <input type="radio"  name="gen" value="Female"/><span>Female</span></td>
        </tr>

        <tr>
        <td><label for="subject">Subject:</label></td>
        <td><input type="text"  name="subject"/></td>
        </tr>

        <tr>
        <td><label for="score">Score:</label></td>
        <td><input type="text"  name="score"/></td>
        </tr>
        </table>

        <input type="reset"name="reset"/>

        <input type="submit"  name="submit" value="submit"/>

        <p><h3>would you like to go to the Home page?<a href="homepage.html">click here</a></h3></p>

</form>
</body>
</html>

this is what i came up with so far but still not validating

1

Are you kidding us with the coding style? (Or lack there of!) How could you possibly expect anybody to be able to read the code while it's written (pasted?) like that?

Please research coding styles/coding conventions, and apply what you learn to your code. Code needs to be readable, or it may as well not be written at all. Programmers tend to spend a lot more time reading code than writing it, so making it easy to understand is extremely important. - You could start with the Wikipedia article on the subject and go from there.

Edited by Atli

0

If you want client-side validation (javascript), I can move this thread to that forum. If on the other hand you want server-side (php) validation, you need to show us the php code you have so far.

Good sites usually have both, client side to warn the user about mistakes before they submit and php for security (js can't be trusted).

0
<!DOCTYPE html>
<html lang="en">
<head>
<title> Resutls</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="utf-8">
<style type="text/css">

body{ background:#9966ff;margin:40px 0px 0px 0px;}

div#topdiv {
    position:absolute;
    top:0px;
    left:0px;
    width:100%;
    color:#ccc;
    background:#9900cc;
    padding:12px;
}

div#buttomdiv {
    position:absolute;
    buttom:0px;
    left:0px; 
    width:100%;
    color:#ccc;
    background:#9900cc;
    padding:6px;

}

</style

</head>


 <body>
 <div id="topdiv">

 <img src="banner.png" alt="banner"/>

 </div>
</head>
</br></br></br></br></br></br></br></br></br></br></br></br>
<body>


<h1>RESULTS</h1>
<h2>WELCOME!</h2> 

<?php
$fname = $_POST["fname"];
$sname = $_POST["sname"];
$age = $_POST["age"];
$gen= $_POST["gen"];
$subject= $_POST["subject"];
$score= $_POST["score"];

echo("<p>Name: $fname");
echo(" $sname</p>");
echo("Age: $age");

if(isset($_POST["gen"])){ 
   $gen=$_POST["gen"];
   echo ("<p>Gender: $gen");
}
 echo("<p>Subject:  $subject");
 echo("<p>Score:  $score");
 if($score >0 && $score<=39)
{
    echo(" You Failed, Study more and keep trying. You can become an A student.</p>");
    echo ('<p><img src="sad.png" margin:5px;/>');
}
  else if($score >=40 && $score<50)
{
    echo ("  You got a C, Good keep studying harder");
    echo ('<p><img src="sad.png" margin:5px;/>');
}
  else if ($score >=50 && $score<70)
{
    echo ("  You got a B, Great work keep working harder for an A");
    echo ('<p><img src="wink.png" margin:5px;/>');
    }
  else if ($score >=70)
{
    echo ("  You got an A, Excellent work keep it up");
    echo ('<p><img src="smiley.png" margin:5px;/>');
}

?>
<p>
Would you like to process another entry?
<a href="formsheet.php">click here</a>
</p>

</br></br></br></br></br></br></br></br>
<div align="right">
<div id="buttomdiv">
 <img src="footer.png" alt="footer"/>

 </div>

<body></body>
<html></html>
1

You haven't closed your </style> tag properly, you still have 2 </head> tags, 2 <html> tags and 3 <body> tags! As suggested before, you need to fix your HTML before you fix the PHP.

Edited by Zagga

Votes + Comments
good spot!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.