|
Posted by J.O. Aho on 04/01/07 16:33
Thad wrote:
> Is there not something like
> javascript in PHP to pull the value of the selected button like
> $answer=image_choice.value.this ?
> If it just cannot be done in a session, I will resign to $_request. I have
> looked at a lot of documentation about $_GET, $_POST and $_REQUEST and just
> cannot get it working. If I have to post first, my server will not allow
> this. Can you help me along this way?
I think you missed the whole concept of a session. Even if you use a session
cookie, you can't manipulate session values with javascript, the data that is
stored in the session cookie is a reference number to data that is stored on a
session file (or database) on the server.
Values from a form has to be sent to the server and fetch those values you use
$_GET, $_POST (it's possible to use $_COOKIE if you use javascript to rewrite
the cookie each time a value in the form is changed) or $_REQUEST.
There is two ways to send data to a php script, either you use the GET method
or the POST method, if you are unsure which method has been used you use
$_REQUEST.
----------------- GET example ------------------
--- page1.php ---
<a href="page2.php?value=1">Send the value 1 to page2.php</a>
--- eof ---
--- page2.php ---
echo $_GET['value'];
--- eof ---
----------------- POST example ------------------
--- page3.php ---
<form action="page4.php">
Value:<input type="text" name="value">
<input type="submit" value="Submit the value">
</form>
--- eof ---
--- page4.php ---
echo $_POST['value'];
--- eof ---
You could replace the page4.php and page2.php with this one:
--- page5.php ---
echo $_REQUEST['value'];
--- eof ---
I do hope you see the difference, a general rule is that a form is a $_POST, a
link is a $_GET (and both are subsets of $_REQUEST), if you want to transfer
the sent value to a variable, then you can do
$value=$_REQUEST['value'];
That ain't so difficult.
If you now want to use a session, you need edit the page2.php, page4.php and
page5.php.
--- page6.php ---
session_start();
echo "Now we will store value=".$_REQUEST['value']." to a session";
$_SESSION['value']=$_REQUEST['value'];
--- eof ---
--
//Aho
Navigation:
[Reply to this message]
|