PDA

Click to See Complete Forum and Search --> : PHP forms


richy
Aug 1st, 2002, 10:20 AM
I've posted a form to a php page which works, but for some reason on my PWS Win 98 machine it won't receive the posts. Normally on php you don't have to call the form do you, just put in the name of the form object name:

e.g. on my form:

<INPUT TYPE='TEXT' NAME='atextbox'>



on my posting to page.

<?php
echo "The information you posted was $atextbox<BR>\n";
?>


It keeps telling me that $atextbox is not defined!

The Hobo
Aug 1st, 2002, 11:33 AM
If there's no information in the box, it won't set it as a variable. But if you are putting information in it, try accessing it like so:


<?php
//if you use PHP 4.1.0 or higher:
echo "The information you posted was " . $_REQUEST['atextbox'] . "<BR>\n";

//earlier version than PHP 4.1.0:
echo "The information you posted was " . $HTTP_SERVER_VARS['atextbox'] . "<BR>\n";
?>


If it works the above way, it means that register_globals is off in the php ini.

The Hobo
Aug 1st, 2002, 11:40 AM
Also, I believe if you are trying to access it in a function, you'll have to tag it as global like so:


<?php
if(isset($submit)) {
parsedata();
} else {
showform();
}

function showform() {
//show our form
}

function parsedata() {
global $donkey;
//in order to print out $donkey, one of our forms
//variables, we have to tag it as global like above
echo $donkey;
}
?>


or you can do it:


<?php
if(isset($_REQUEST['submit'])) {
parsedata();
} else {
showform();
}

function showform() {
//show our form
}

function parsedata() {
echo $_REQUEST['donkey'];
}
?>


As the variables in $_REQUEST are superglobals, they are accessable anywhere in the script. This is also the new PHP standard.

Let me know if any of this helps.

phpman
Aug 1st, 2002, 01:41 PM
is it a warning message? you have to turn that off in the php.ini file. or you can define you variables.

richy
Aug 2nd, 2002, 03:11 AM
Cheers everyone I'll try your ideas tonight, and get back to you on monday to say if they work. but I'm sure they will work.

Thanks alot.