Page 1 of 1

[SOLVED] Function help??

Posted: Sun Aug 01, 2004 11:50 am
by fresh
hey

Im trying to call a function within a form element, could someone show me how to do so, here's my html form and PHP script:

Code: Select all

<form action="blah.php" method="post"> <-- may not be needed
Laboratory:
<div style='border:#323E4A 1px solid;width:400;height:80;color:#AAC9E8'>
<table border=0 cellpadding=0 cellspacing=0>
<td width=400 height=80>

Code: Select all

<?php
function chk() {
$try = $_POST['test'];
$answer = "apple";
$right =  "right";
$wrong =  "wrong";
if ($answer != $try) {
echo "".$wrong."";
} else {
echo "".$right."";
}}
?>

Code: Select all

&lt;/td&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;table border=0 cellpadding=0 cellspacing=0&gt;
&lt;td&gt;
&lt;input type="text" name="test"&gt; 
&lt;input type="submit" name="sub" value="Inject"&gt;
&lt;/td&gt;
&lt;/table&gt;
&lt;/form&gt;
So I'm trying to call a function when somone hits the inject submit button and echo either the right or wrong message in the laboratory div box, I have no idea how to do this, so a simple example would be much appreciated, thanks :)

Posted: Sun Aug 01, 2004 1:46 pm
by fresh
hey, nevermind, figured it out.. thanks :)

Posted: Sun Aug 01, 2004 10:23 pm
by John Cartwright
you should generaly post your solution for the well being of ppl reading the topic :)

Posted: Mon Aug 02, 2004 1:21 am
by fresh
well, I just snuffed the function call, and then just substitued the call with a new page which would echo the vars from the form page... simulating the same effect.. nothing much to share.. sorry :(