MGCJerry
06-27-2002, 05:17 PM
Ok, I'm totally stumpted on this... I'm making another script for my RPG, and well it does my check() function without clicking the submit button... How can I have the page where it displayes only the form and, when a user clicks the submit button it checks the data...
In short... It isnt waiting for the user to click "submit" before it does the check() function...
This is getting me really mad. Does any php gurus have any suggestions?
The script worked all the way up till I put the HTML into the script...
Thanks :)
Edit
I removed the code to save space in this post. My script works now :)
The Prohacker
06-27-2002, 06:14 PM
You want to check the text someone puts in an input before they click submit??
Thats not a PHP program, you need JavaScript todo that for you :D
MGCJerry
06-27-2002, 06:16 PM
I want it to check the data after they fill in form.
aussiejosh
06-28-2002, 01:55 AM
What about this?:
<?php
if(!$submit) // or whatever the name of the <input type="submit"> is
{
?>
HTML Code for the form goes here. Don't worry about escaping double quotes because
you're outside the PHP tags (of course, you can echo ""; the HTML if you like).
Change
<form action=\"".check($check)."\" method=\"POST\">
To:
<form action="<?php echo $PHP_SELF; ?>" method="POST">
And change:
<input type=\"submit\" name=\"B1\" value=\"Submit\">
To:
<input type="submit" name="submit" value="Submit">
I'm not sure why the <input type="reset"> has the same name as submit (or even a name
at all) because it's handled by the browser and the PHP script (as far as I know) never
finds out that you hit the reset button.
<?php
exit;
}
// If we get below here, the submit button has been pressed
function check()
{
// function code
}
// do the check here.. something like this should work:
if(!check($check))
{
?>
check() returned false so print the HTML with the error
<?php
exit;
}
// do whatever you want to do if the check() function returns true
It should work, but I can't guarentee (sp?) it will. I haven't slept for a while so i'm not thinking that well :(
PM or Email me if it doesn't work or something :)
Josh
MGCJerry
06-28-2002, 07:35 AM
I got it working now using your code.
I had to play with your code a little though, but it was mainly the placement of my html.
I see what I did wrong through. I wasnt thinking in the same process of php. This is also the first time I had to use a user defined function. :)
Now I gotta go and set up the rest of it. I think the graphs will also give the user a better understanding of each race :)
Thanks again :)
MGCJerry
06-28-2002, 09:12 AM
I finished the script :)
You can check it out here (http://www.2thextreme.org/Attributes.php)...
Comments welcome :)
I'm really liking php... Now to move onto including MySQL databases :eek2:
aussiejosh
06-28-2002, 10:40 AM
I'm glad it worked, I wasn't too sure whether or not it would.
Now that you understand the basics of PHP, MySQL won't be too hard (it wasn't in my experience, anyway). :)
Josh