Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mmmdreg

macrumors 65816
Original poster
Apr 14, 2002
1,393
0
Sydney, Australia
This is a really basic question.. What do I use to do simple things like make forms on the web with radio buttons etc that you can submit and the data gets analysed and then gives you feedback?
 
This is a really basic question.. What do I use to do simple things like make forms on the web with radio buttons etc that you can submit and the data gets analysed and then gives you feedback?

I'd say if you're asking those questions, you really need to sit down with a current (x)html book and start from scratch. I don't mean that as an insult or put-down. I do think it helps to have an understanding.
That said, I'm sure something like Dreamweaver could help you build those forms.
 
To do something basic and simple like this you need to know HTML (for markup), CSS (optional — but you probably want to present your content so it is attractice) and a server side scripting language (like php).

On top of this you would probably add some javascript to do some client side validation, as it takes some load off the server and speeds things up, but you still need to do it server side in case javascript is switched off.

Here is a quick example, it is not very good because I am only learning:

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>Favourite Colour Poll</title>
	
	<style type="text/css" media="screen">
		body {
			font: 75% "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
		}
		
		#wrap {
			width: 33em;
			margin: 0 auto;
		}
		
		fieldset {
			border: 1px solid #ccc;
			margin-bottom: 1em;
		}
		
		legend {
			border: 1px dotted #ccc;
			padding: .5em;
			background: #ececec;
		}
		
		p.centre {
			text-align: center;
		}
		
		input#submit {
			font-size: 1.5em;
		}
	</style>
	
</head>

<body>
	<div id="wrap">
PHP:
<?
			if(isset($_POST['submit'])) {		
				if(!isset($_POST['lang']) || !isset($_POST['colour'])) {
					echo("<h1>Form not Complete.</h1>");
					echo("<p><a href=\"{$_SERVER['PHP_SELF']}\">Try Again »</a></p>");
				}
				else {
					switch ($_POST['lang']) {
						case 'us':
							$colour = "color";
							$favourite = "favorite"; 
							break;
				
						case 'uk':
							$colour = "colour";
							$favourite = "favourite";					
							break;
					}
					echo("<h1>Your $favourite $colour is {$_POST['colour']}.</h1>");
					echo("<p><a href=\"{$_SERVER['PHP_SELF']}\">Vote Again »</a></p>");
				}
			}
			else {
		?>
HTML:
		<form action="<? $_SERVER['PHP_SELF'] ?>" method="post" accept-charset="utf-8">
			<fieldset>
				<legend>Vote:</legend>
				<p><input type="radio" name="colour" value="red" id="red" /> <label for="red">Red</label></p>
				<p><input type="radio" name="colour" value="green" id="green" /> <label for="green">Green</label></p>
				<p><input type="radio" name="colour" value="blue" id="blue" /> <label for="blue">Blue</label></p>
			</fieldset>
		
			<fieldset>
				<legend>Language:</legend>
				<p><input type="radio" name="lang" value="us" id="us" /> <label for="us">American</label></p>
				<p><input type="radio" name="lang" value="uk" id="uk" /> <label for="uk">English</label></p>
			</fieldset>
		
			<p class="centre"><input type="submit" id="submit" name="submit" value="Send!" /></p>
		</form>
PHP:
<? } ?>
HTML:
	</div>
</body>
</html>
 

Attachments

  • poll.php.txt
    2.2 KB · Views: 122
I'd say if you're asking those questions, you really need to sit down with a current (x)html book and start from scratch. I don't mean that as an insult or put-down. I do think it helps to have an understanding.
That said, I'm sure something like Dreamweaver could help you build those forms.

i dont think that he needs to buy dreamweaver just to do those things he could use Nvu.
 
Along these lines, anyone know a good place to learn the php necessary to make a simple form that will either send a text file in an email, or store the entries in a database to be retrieved later? I can work with SQL fairly well, as far as setting up a database to be used, but I haven't yet figured out the php side of the application, or how to associate it with a form effectively. The database would probably be better, btw, so if there's a secure way to access it (just a password will suffice, it's not going to be high profile), that would also be quite helpful. BTW, elppa, what you posted was very helpful to me already, it answered some of my previous questions about how to make that type of thing work.

jW
 
the data gets analysed and then gives you feedback

This is not an HTML (web page) function. This part of your request requires that the form data be directed into a database-type program (either on the webserver itself, if you are intending to give the users instant feedback) or on another machine for off line anaysis.

This is not something you are going to program yourself, grasshopper.
Do some Google searching for Web forms analysis and web survey tools. You'll find that there are companies, like SurveyMonkey, who sell this as a service, and you will find a large number of scripts and databases in various languages that do similar things.

The problem is at your level of experience, you won't have the first foggiest clue how to implement the various scripts available.

So I suggest you either go with a prepackaged service, or you engage some realtime help from someone with experience. You may need to pay money for either or both of these.
 
Along these lines, anyone know a good place to learn the php necessary to make a simple form that will either send a text file in an email, or store the entries in a database to be retrieved later? I can work with SQL fairly well, as far as setting up a database to be used, but I haven't yet figured out the php side of the application, or how to associate it with a form effectively. The database would probably be better, btw, so if there's a secure way to access it (just a password will suffice, it's not going to be high profile), that would also be quite helpful. BTW, elppa, what you posted was very helpful to me already, it answered some of my previous questions about how to make that type of thing work.

jW

This is how you connect to a MySQL database:

PHP:
$host = "localhost"; // or whatever the server is
$user = "root"; // or whatever your username is
$password = "myGreatHardToHackPassword"; // or whatever your password is

$connection = mysql_connect("$host","$user","$password")
	or exit ("Could not connect to server");

// Select the Database
$db = mysql_select_db("MyDatabase") // or whatever your database name is
	or exit ("Cannot connect to database at present.");

To select a single row (record) from a table:
PHP:
$query = mysql_query("SELECT * FROM tablename WHERE id LIKE '1'");

To display a single row from a table:
PHP:
$row = mysql_fetch_array($query);

echo $row['field1']; // will display the contents of the field called "field1" for row 1
echo $row['field2']; // will display the contents of the field called "field1" for  row 1

// etc

// -- or --

extract($row); // creates variable names from the keys in the array

echo $field1;
echo $field2;

To select all rows (records) from a table:
PHP:
$query = mysql_query("SELECT * FROM tablename");

To find out how many rows your query returned:
PHP:
$number = mysql_num_rows($query);
echo "There are $number rows in the table.";

To select many rows (records) from a table:
PHP:
$query = mysql_query("SELECT id, name, price FROM tablename WHERE price > '4.50'");

To display multiple rows:
PHP:
echo "<h2>Products which cost more than €4.50</h2>";
while($row = mysql_fetch_array($query)) {
 //  The operations in this block are performed on each row from the table in turn until there are no more rows left!
echo "<h3>{$row['id']}</h2>";
echo "<p>{$row['name']} ({$row['price']})</p>";
}


To insert a row:
PHP:
$query = mysql_query("INSERT INTO tablename (field1,field2) VALUES ('value1','value2')");


To update a row:
PHP:
$query = mysql_query("UPDATE tablename SET field1='value1', field2='value2' WHERE id LIKE '1'");

To delete a row: (use with caution!)
PHP:
$query = mysql_query("DELETE FROM tablename WHERE id LIKE '1'");

These are for using with the MySQL database, but similar functions are available for use with other databases. In some cases they are almost identical (mssql_query, mssql_num_rows etc.)

You will need to add more sophistication - statements to check whether the queries were actually successful, but I hope that helps in some small way.

PS: If anyone sees any syntax erros please let me know. I typed these from memory.
 
Thanks so much, elppa! That's awesome information. Where did you learn php, btw? I've been teaching myself by looking at existing code (mostly phpbb), and I've done the beginnings of the tutorials over at the w3schools (or whatever the site is called).

jW
 
I'd say if you're asking those questions, you really need to sit down with a current (x)html book and start from scratch. I don't mean that as an insult or put-down. I do think it helps to have an understanding.
That said, I'm sure something like Dreamweaver could help you build those forms.

Thanks. I was more referring to the serverside analysis part. I guess PHP is the way to go?

George
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.