Page 1 of 1

Accessing Form Elements

Posted: Sat Aug 04, 2007 12:03 pm
by Deerman
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I want to access form elements (text boxes) in HTML via php. Can this be done.

Thank you

Code: Select all

<html>

<head>
<title>New Page 1</title>
</head>

<?php


// Want to access the form elements from here.


?>

<body>

<form name="puzzle">
	<p align="center"><font size="5">Sudoku</font><font size="5"> Solver<br>
	</font><br>
	<input type="text" name="T1" size="1">&nbsp;
	<input type="text" name="T2" size="1">&nbsp;
	<input type="text" name="T3" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T5" size="1">&nbsp;&nbsp;
	<input type="text" name="T6" size="1">&nbsp;&nbsp;
	<input type="text" name="T7" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T8" size="1">&nbsp;&nbsp;
	<input type="text" name="T9" size="1">&nbsp;&nbsp;
	<input type="text" name="T10" size="1"><br>
	<input type="text" name="T11" size="1">&nbsp;
	<input type="text" name="T12" size="1">&nbsp;
	<input type="text" name="T13" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T14" size="1">&nbsp;&nbsp;
	<input type="text" name="T15" size="1">&nbsp;&nbsp;
	<input type="text" name="T16" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T17" size="1">&nbsp;&nbsp;
	<input type="text" name="T18" size="1">&nbsp;&nbsp;
	<input type="text" name="T19" size="1"><br>
	<input type="text" name="T23" size="1">&nbsp;
	<input type="text" name="T24" size="1">&nbsp;
	<input type="text" name="T25" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T27" size="1">&nbsp;&nbsp;
	<input type="text" name="T28" size="1">&nbsp;&nbsp;
	<input type="text" name="T29" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T31" size="1">&nbsp;&nbsp;
	<input type="text" name="T32" size="1">&nbsp;&nbsp;
	<input type="text" name="T33" size="1"></p>
	<p align="center"><input type="text" name="T34" size="1">&nbsp;
	<input type="text" name="T35" size="1">&nbsp;
	<input type="text" name="T36" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T38" size="1">&nbsp;&nbsp;
	<input type="text" name="T39" size="1">&nbsp;&nbsp;
	<input type="text" name="T40" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T42" size="1">&nbsp;&nbsp;
	<input type="text" name="T43" size="1">&nbsp;&nbsp;
	<input type="text" name="T44" size="1"><br>
	<input type="text" name="T45" size="1">&nbsp;
	<input type="text" name="T46" size="1">&nbsp;
	<input type="text" name="T47" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T49" size="1">&nbsp;&nbsp;
	<input type="text" name="T50" size="1">&nbsp;&nbsp;
	<input type="text" name="T51" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T53" size="1">&nbsp;&nbsp;
	<input type="text" name="T54" size="1">&nbsp;&nbsp;
	<input type="text" name="T55" size="1"><br>
	<input type="text" name="T56" size="1">&nbsp;
	<input type="text" name="T57" size="1">&nbsp;
	<input type="text" name="T58" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T60" size="1">&nbsp;&nbsp;
	<input type="text" name="T61" size="1">&nbsp;&nbsp;
	<input type="text" name="T62" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T64" size="1">&nbsp;&nbsp;
	<input type="text" name="T65" size="1">&nbsp;&nbsp;
	<input type="text" name="T66" size="1"></p>
	<p align="center"><input type="text" name="T67" size="1">&nbsp;
	<input type="text" name="T68" size="1">&nbsp;
	<input type="text" name="T69" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T71" size="1">&nbsp;&nbsp;
	<input type="text" name="T72" size="1">&nbsp;&nbsp;
	<input type="text" name="T73" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T75" size="1">&nbsp;&nbsp;
	<input type="text" name="T76" size="1">&nbsp;&nbsp;
	<input type="text" name="T77" size="1"><br>
	<input type="text" name="T78" size="1">&nbsp;
	<input type="text" name="T79" size="1">&nbsp;
	<input type="text" name="T80" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T82" size="1">&nbsp;&nbsp;
	<input type="text" name="T83" size="1">&nbsp;&nbsp;
	<input type="text" name="T84" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T86" size="1">&nbsp;&nbsp;
	<input type="text" name="T87" size="1">&nbsp;&nbsp;
	<input type="text" name="T88" size="1"><br>
	<input type="text" name="T89" size="1">&nbsp;
	<input type="text" name="T90" size="1">&nbsp;
	<input type="text" name="T91" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T93" size="1">&nbsp;&nbsp;
	<input type="text" name="T94" size="1">&nbsp;&nbsp;
	<input type="text" name="T95" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="text" name="T97" size="1">&nbsp;&nbsp;
	<input type="text" name="T98" size="1">&nbsp;&nbsp;
	<input type="text" name="T99" size="1"></p>
	<p align="center"><input type="button" name="button" value="   Solve   ">
	
</form>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Aug 04, 2007 12:52 pm
by iknownothing
You need to POST your data first if you wish to input the textbox values into a database or similar.

Code: Select all

$t1 = $_POST['t1'];

If you want to extract information out of a databse or similar, and put it into your textboxes, you would do the following:

Code: Select all

<input type="text" value="<?php echo $t1; ?>" name="T1" size="1">

If you want to change cetain aspects of the element, eg, height, value etc, without refreshing the page you will need to use Javascript.

Code: Select all

var t1 = document.getElementById('t1');
t1.height = 'whatever';

RE:

Posted: Sat Aug 04, 2007 12:55 pm
by Deerman
There is no data to "POST"

This code produces a 9X9 Sudoku grid. The user will fill in some numbers into the HTML text fields and I want php to be able to read all of the text fields to see which ones have a number in them.

Thanks.

Posted: Sat Aug 04, 2007 12:58 pm
by iknownothing
If you want to use PHP, then you will, infact need to POST your data first.

It looks to me as though you would rather use Javascript.

Re: RE:

Posted: Sat Aug 04, 2007 1:13 pm
by superdezign
Deerman wrote:There is no data to "POST"

This code produces a 9X9 Sudoku grid. The user will fill in some numbers into the HTML text fields and I want php to be able to read all of the text fields to see which ones have a number in them.

Thanks.
So? When they are done, don't they have to click a button that tells you so? Then, you get all of the POSTED data and process it to see if they completed it validly or not.

Posted: Sat Aug 04, 2007 1:14 pm
by miro_igov
C'mon guyz, he did not specified any form method and the default is GET. $_REQUEST is universal.

RE:

Posted: Sat Aug 04, 2007 2:47 pm
by Deerman
Hey everybody, thanks for the answers. I'm a complete beginner in PHP. That's why I'm finding difficulty with this. Could anybody post a short example (using code) that does what I asked. I just need an example to work off of.

Thank you.

RE:

Posted: Sat Aug 04, 2007 4:35 pm
by Deerman
I look at a tutorial... typed this code in:

Code: Select all

import_request_variables("gp", "formval_");

echo "Ship = ".$formval_T1;
echo "<br />";
but still no go.

It says that T1 is undefined.

Posted: Sat Aug 04, 2007 10:32 pm
by RobertGonzalez
Answer this question: Do you want the grid to be a form-field-per-box setup that, when the user enters a number between 1 and 9, that nu,ber automatically get fetched and used by the application? Or are you expecting the user to complete the grid and hit a button?

Posted: Tue Aug 07, 2007 12:02 pm
by Deerman
I'm expecting the user to enter all of the data then press a button.

Posted: Tue Aug 07, 2007 5:05 pm
by RobertGonzalez
Deerman wrote:I'm expecting the user to enter all of the data then press a button.
Then once the form is submitted, all of the form data will be in the $_POST superglobal array.

Posted: Wed Aug 08, 2007 7:16 am
by ghadacr
If you want the form to be submitted to it self, then use

Code: Select all

<form method=\"post\" action=\"<?PHP $_SERVER[PHP_SELF]\ ?>">

Posted: Wed Aug 08, 2007 7:22 am
by VladSun
Some of the members here have shown me some days ago, that using $_SERVER[PHP_SELF] is vulnerable to XSS attacks. You should use empty action intstead - that means the action is the current page.

Posted: Wed Aug 08, 2007 7:34 am
by ghadacr
That is true. PHPSELF is not good, but if the script is only going to be used by your self then it's ok.......