Jump to content

Scrutinizing fields in a webform?


Recommended Posts

Dear All,

 

I am writing a code to register new users on my website http://www.computationalphotography.in/registration.php. I want the page to check the entries in each field and return an error if any field is left blank or an invalid data-type has been entered. Could you please suggest ways to achieve this?

Below is my code for the form:

 

<html>

<head>

	<title>

	Photography Experiment Registration
	</title>

</head>

<body>

	<h1>

	Questionnaire
	</h1>

	<h3>
	We would like to know about your background and interests in photography. For each multiple-choice question, please circle all answers that apply.</h3>
		<form method="post" action="registration.php">
		Note that all fields marked with * are mandatory
		<br>
		<br>
		Name*
		<input name="name" type="text">
		<br>
		<br>
		Email&nbsp	

		<input name="email" type="text">
		<br>
		<br>
		Password<pre></pre>
		<input type="password" name="password">
		<br>
		<br>
		Re-Type Password<pre></pre>
		<input type="password" name="password">
		<br>
		<br>			
		1.) Roughly How many pictures do you take each year?
		<br>
		<br>			
		<input name="o1q1" type="radio" value="a">		
		a) a few: <10 in a year
		<br>
		<input name="o2q1" type="radio" value="b">
		b) many: probably 100's a photos a year
		<br>
		<input name="o3q1" type="radio" value="c">
		c) a lot: probably 1000's of photos a year
		<br>
		<br>

		2.) Do you share your pictures with anyone?
		<br>
		<input name="o1q2" type="radio" value="a">
		a) No
		<br>
		<input name="o2q2" type="radio" value="b">
		b) Yes, but only with friends or family
		<br>
		<input name="o3q2" type="radio" value="c">
		c) Yes, I share with friends or family and also post on public sites such as Flickr, Picasaweb, or Snapfish for anyone to see.
		<br>
		<input name="o4q2" type="radio" value="d">
		d) Yes, I share frequently and I have also published my photos in books or magazines, or exhibited my photos in shows.	
		<br>
		<br>

		3.) How much training in photography have you had?
		<br>
		<input name="o1q3" type="radio" value="a">
		a) None
		<br>
		<input name="o2q3" type="radio" value="b">
		b) Some, but it's self-taught from books or websites
		<br>
		<input name="o3q3" type="radio" value="c">	
		c) Quite a bit: I have taken courses in photography
		<br>
		<input name="o4q3" type="radio" value="d">	
		d) A lot:I have completed a degreee or certificate in the subject
		<br>			
		<br>

		4.) How do you describe yourself as a photographer?
		<br>
		<input name="o1q4" type="radio" value="a">
		a) A novice:someone who takes a few pictures occasionally
		<br>
		<input name="o2q4" type="radio" value="b">
		b) An amateur:someone who takes many photos, but doesn't usually share them
		<br>
		<input name="o3q4" type="radio" value="c">
		c) An enthusiast:someone who loves to take pictures, possibly shows them with oters on public sites, or who might own a DSLR, or frequently uses a camera in other than "automatic mode"
		<br>
		<input name="o4q4" type="radio" value="d">
		d) An expert:skilled photographer who has published their work, or exhibited their work in shows, or has been paid for their work
		<br>
		<br>

		5.) Do you have artistic training or exposure?
		<br>
		<input name="o1q5" type="radio" value="a">
		a) No
		<br>
		<input name="o2q5" type="radio" value="b">
		b) I visit museums or art galleries
		<br>
		c) I have studied art: please describe
		<br>
			<textarea name="data5c" cols="50" rows="5">
			</textarea>					
		<br>				
		d) I am a practicing artist: please describe
		<br>
			<textarea name="data5d" cols="50" rows="5">
			</textarea>
		<br>
		<br>
		6.) Some optional information, if you don't mind. We respect your privacy.
		<br>
		<br>
		Age
			<br>
			<textarea name="6a" cols="1" rows="1">
			</textarea>
			<br>
			<br>
		Gender
		<br>
				<input name="male" type="radio" value="a">
				a) Male
		<br>
				<input name="female" type="radio" value="b">
				b) Female
		<br>
		<br>
		Languages Spoken	
			<br>
			<textarea name="6b" cols="25" rows="2">
			</textarea>
			<br>
			<br>
		Languages Read
			<br>
			<textarea name="6c" cols="25" rows="2">
			</textarea>
			<br>
		<br>
		<br>
		<input type="submit" value="Send">

		<input type="reset"  value"Reset">

		</form>

</body>

</html>

 

 

Thank you for your help. I have a few more queries regarding this web-form, but will mention them once this query is resolved.

Link to comment
Share on other sites

Dear All,

 

I want to check that the user has entered a value of the correct data-type in the fields which are marked by * in my website www.computationalphotography.in/registration.php. Below is the code for the same, my form is not returning the value that I intend

it to return, i.e. an error message for wrongly/not entering data. Please help me out in this regard:

 

<html>

<head>

	<title>

	Photography Experiment Registration
	</title>

</head>

<body>

	<h1>

	Questionnaire
	</h1>

	<h3>
	We would like to know about your background and interests in photography. For each multiple-choice question, please circle all answers that apply.</h3>
		<?php
		if($_POST['Submit']== "Submit")
		{
		 $errormessage="";
			if(empty($_POST['name']))
			{
				$errormessage = "<li>You forgot to enter a name</li>";
			}
			if(empty($_POST['email']))
			{
				$errormessage = "<li>You forgot to enter an email</li>";
			}
			if(empty($_POST['password']))
			{
				$errormessage = "<li>You forgot to enter password</li>";
			}
			$varname = $_POST['submit'];
			$varmail = $_POST['email'];
			$varpass = $_POST['password'];
			if(!empty($errorMessage))
				{
			echo("<p>There was an error with your form:</p>\n");
			echo("<ul>" . $errorMessage . "</ul>\n");
				}
		}
		?>
		<br>
		<br>
		<form method="post" action="registration.php">
		Fields marked with * are mandatory
		<br>
		<br>
		Name*
		<input name="name" type="text">
		<br>
		<br>
		Email*&nbsp	

		<input name="email" type="text">
		<br>
		<br>
		Password*<pre></pre>
		<input type="password" name="password">
		<br>
		<br>
		Re-Type Password*<pre></pre>
		<input type="password" name="password">
		<br>
		<br>			
		1.) Roughly How many pictures do you take each year?*
		<br>
		<br>			
		<input name="o1q1" type="radio" value="a">		
		a) a few: <10 in a year
		<br>
		<input name="o2q1" type="radio" value="b">
		b) many: probably 100's a photos a year
		<br>
		<input name="o3q1" type="radio" value="c">
		c) a lot: probably 1000's of photos a year
		<br>
		<br>

		2.) Do you share your pictures with anyone?*
		<br>
		<input name="o1q2" type="radio" value="a">
		a) No
		<br>
		<input name="o2q2" type="radio" value="b">
		b) Yes, but only with friends or family
		<br>
		<input name="o3q2" type="radio" value="c">
		c) Yes, I share with friends or family and also post on public sites such as Flickr, Picasaweb, or Snapfish for anyone to see.
		<br>
		<input name="o4q2" type="radio" value="d">
		d) Yes, I share frequently and I have also published my photos in books or magazines, or exhibited my photos in shows.	
		<br>
		<br>

		3.) How much training in photography have you had?*
		<br>
		<input name="o1q3" type="radio" value="a">
		a) None
		<br>
		<input name="o2q3" type="radio" value="b">
		b) Some, but it's self-taught from books or websites
		<br>
		<input name="o3q3" type="radio" value="c">	
		c) Quite a bit: I have taken courses in photography
		<br>
		<input name="o4q3" type="radio" value="d">	
		d) A lot:I have completed a degreee or certificate in the subject
		<br>			
		<br>

		4.) How do you describe yourself as a photographer?*
		<br>
		<input name="o1q4" type="radio" value="a">
		a) A novice:someone who takes a few pictures occasionally
		<br>
		<input name="o2q4" type="radio" value="b">
		b) An amateur:someone who takes many photos, but doesn't usually share them
		<br>
		<input name="o3q4" type="radio" value="c">
		c) An enthusiast:someone who loves to take pictures, possibly shows them with oters on public sites, or who might own a DSLR, or frequently uses a camera in other than "automatic mode"
		<br>
		<input name="o4q4" type="radio" value="d">
		d) An expert:skilled photographer who has published their work, or exhibited their work in shows, or has been paid for their work
		<br>
		<br>

		5.) Do you have artistic training or exposure?*
		<br>
		<input name="o1q5" type="radio" value="a">
		a) No
		<br>
		<input name="o2q5" type="radio" value="b">
		b) I visit museums or art galleries
		<br>
		c) I have studied art: please describe
		<br>
			<textarea name="data5c" cols="50" rows="5">
			</textarea>					
		<br>				
		d) I am a practicing artist: please describe
		<br>
			<textarea name="data5d" cols="50" rows="5">
			</textarea>
		<br>
		<br>
		6.) Some optional information, if you don't mind. We respect your privacy.
		<br>
		<br>
		Age
			<br>
			<textarea name="6a" cols="1" rows="1">
			</textarea>
			<br>
			<br>
		Gender
		<br>
				<input name="male" type="radio" value="a">
				a) Male
		<br>
				<input name="female" type="radio" value="b">
				b) Female
		<br>
		<br>
		Languages Spoken	
			<br>
			<textarea name="6b" cols="25" rows="2">
			</textarea>
			<br>
			<br>
		Languages Read
			<br>
			<textarea name="6c" cols="25" rows="2">
			</textarea>
			<br>
		<br>
		<br>
		<input type="submit" name="Submit" value="Submit">

		<input type="reset"  value"Reset">

		</form>

</body>

</html>
[code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.