Page 1 of 1
Running code from a form - newbie urgent!! :P
Posted: Tue Dec 16, 2003 3:21 am
by Azhrarn
Hi guys, I kind of got spoilt last time when you answered so quickly, so here I am again.
Is there any way of having a form in a page that runs some code "under" it rather than loading the same or another page?
In psudocode
if certain conditions arise {
form
input
submit
if submit, run the following code
}
else
do something else
Hope its clear

cheers!!
Azh
Posted: Tue Dec 16, 2003 6:11 am
by qads
Code: Select all
<?php
if(isset($_POST['submit']))
{
echo "your name is ".$_POST['name'];
}
if(!isset($_POST['submit']))
{
echo '
<form name="f" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
your name:<input type="text" name="name"><br />
<input type="submit" name="submit">
</form>';
}
?>
if form is not set
show form
if form is set
show output...
helpful?
Posted: Tue Dec 16, 2003 6:25 am
by Azhrarn
ok almost perfect, but is there any way of running some code that is submitted by a form without having to reload the page?
its because i have quite a few variables and I don t want to have to dump everything in $_SESSION...
Thanks!!!
Posted: Tue Dec 16, 2003 6:47 am
by twigletmac
You need to reload the page because PHP is server side, the script can't run unless the server is called. Perhaps we can get a clearer picture if you show us some of the code or explain what variables would need to be passed. For example it may be possible to pass variables as hidden fields within the form.
Mac
Posted: Tue Dec 16, 2003 6:52 am
by Azhrarn
ok twigletmac thx a lot!
I sorted it out with hidden fields and passing anything I needed t SESSION.
Thanks for the help guys!!
Cheers
Azhrarn