Running code from a form - newbie urgent!! :P

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Azhrarn
Forum Newbie
Posts: 12
Joined: Mon Dec 15, 2003 4:32 am

Running code from a form - newbie urgent!! :P

Post 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 :P
cheers!!
Azh
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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?
Azhrarn
Forum Newbie
Posts: 12
Joined: Mon Dec 15, 2003 4:32 am

Post 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!!!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Azhrarn
Forum Newbie
Posts: 12
Joined: Mon Dec 15, 2003 4:32 am

Post 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
Post Reply