Page 1 of 1
Form on same page as validator!
Posted: Sun Aug 31, 2003 4:39 pm
by wmasterj
My case:
I got a form
Code: Select all
<?php
echo "<hr width='520' align='left'><form action="admin.php?page=siteEditor.php" method="post"><font face='verdana' size='2'><b>Create new section:</b></font>";
echo "<br><font face='verdana' size='1'>Section name: <input type="text" name="sectionname" class="editor"><br><br><input type="submit" name="submitsection" value="Create New Section" class="editor"><br>";
echo "</font><br><br>";
?>
and then i got the piece of code which, is on the same page and which takes care of the data inputted.
Code: Select all
<?php
//Adding a new section
if(isset($submitsection))
{
echo "Yes I got in!";
sectionAdd($sectionname);
//Resetting variables so you can make a new .one withouT
//refreshing the page
$submitsection = "";
$sectionname = "";
}
?>
The thing is nothing happens, and iv'e spent a very long time trying to figure it out...

Not even tha text
Yes I got in! shows, soo....
?>
Posted: Sun Aug 31, 2003 5:01 pm
by volka
please read
Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+.
It's not a sticky thread for nothing and might solve your problem

Posted: Sun Aug 31, 2003 5:04 pm
by wmasterj
Things is i got -> register_globals on
Posted: Sun Aug 31, 2003 5:36 pm
by JAM
Dont take me wrong, but are you sure?
I happen to have it off, but after changing the code to
Code: Select all
if(isset($_POST['submitsection']))
...it worked here just as you pasted it.
Re: Form on same page as validator!
Posted: Sun Aug 31, 2003 5:45 pm
by McGruff
Does it work like this, with the form action set to $_SERVER['PHP_SELF']?
Code: Select all
<?php
echo '<hr width="520" align="left" /><form action="' . $_SERVER[PHP_SELF] . '" method="post"><font face="verdana" size="2"><b>Create new section:</b></font>';
echo '<br><font face="verdana" size="1">Section name: <input type="text" name="sectionname" class="editor"><br /><br /><input type="submit" name="submitsection" value="Create New Section" class="editor"><br />';
echo '</font><br /><br />';
?>
Side note: if you use single quotes to declare html strings it saves a lot of escaping. Jump out of the string & concatenate to add a var.
Have also added a space and / to empty tags like <br /> which is the normal, xhtml compliant, way to write them nowadays.
I personally don't llike to have any html in my php scripts but that's another issue.
Posted: Sun Aug 31, 2003 5:47 pm
by wmasterj
I got it!
The things was that the rate of success was very inconsistent and so instead of testing $submit section i tested $sectionname:
Code: Select all
<?php
if(isset($_POST['sectionname']) && ($_POST['sectionname'] != ""))
{
sectionAdd($_POST['sectionname']);
//Resetting variables so you can make a new one without
//refreshing the page
$_POST['sectionname'] = "";
}
?>
so i changed the stuff to use $_POST -> but that wasn't the problem still...very strange, cuz' sometimes it worked and sometimes it didn't...but then i used the $sectionname variable instead and it's
works like a charm
Thx guys for the input

Posted: Sun Aug 31, 2003 5:51 pm
by wmasterj
thx McGruff i'll start using tha < /> thing
And thanks for going trough and changing the text and stuff...
Why i use double-qoutes is because i can use variables without having to '.$var.' them instead i can just put it rigth in there and PHPedit higlights it nicely so i can se it..
Thx again!
