We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › html forms getting started
Page Index Toggle Pages: 1
html forms? getting started (Read 436 times)
html forms? getting started
Aug 2nd, 2009, 7:12pm
 
i'm new to processing, i've been using flash.
(i'm in the process of converting to linux, from windows)

i'm a math teacher and I am making online home work.


i want to send info from a processing file, like an html form.

then i already know how to take that info, and use php and mySql to keep records.

for example.

how would I make a program that:
*makes 2 squares, one red one blue.
*the user clicks one.
*the color of the square is stored in a string called 'userChoice'
*then the info is sent "post" to a php file that has the code:

<?php
echo 'user choose : '.$_POST['userChoice'];
?>




Re: html forms? getting started
Reply #1 - Aug 3rd, 2009, 5:23am
 
* Making the squares is trivial, once you went through the tutorials (or look at the examples). Hints: rect() and fill().
* Reacting on click on a rectangle is less easy: Processing has no notion of clickable object, once the rectangle is drawn, it is just a bunch of pixels. So you detect the click (eg. with mousePressed() callback) at the whole sketch level and check that it is within the bounds of one or the other rectangle.
You can also make your own Rectangle class to make smarter rectangles...
* Trivial.
* Send the info: you can use link(), although it might spawn a browser window. Alternatively, you can use Java stuff to invoke an URL, I used that to upload data (images).
It would look like:
Code:
	URL url = new URL(uploadURL); // throws MalformedURLException
connection = (HttpURLConnection) url.openConnection();  // throws IOException
connection.setRequestMethod("GET");  // With GET method
etc.

and of course, the userChoice parameter put after the URL.
Page Index Toggle Pages: 1