Page 1 of 1

HTML form tags (+ function) with PHP?

Posted: Tue Apr 20, 2010 6:21 am
by pookie
Hi,

I have a problem with a PHP task. I'm completely new to this and really have no clue how to solve this. It can't be that hard? It's a HTML form, I have two "option value" with "crypt" and "decrypt" and when I pick crypt I want a function to execute (show the crypt text from the text input box) after clicking OK. When I pick decrypt I want another function to execute (show the decrypt text from the text input). How do you solve this, how do I read HTML form tags with PHP? It works now, but the form shows both of them. All I want to do is to connect the php functions to the two different values. Does anyone know how to do this? :)

Code: Select all


<?php 
$message = $_POST["message"];
?>

(......... function code etcetc.)
 
<h2>Test 1</h2>

<form method="post" action="myform.php">
<textarea name="message" size="5" rows="2" cols="30"></textarea><br/><br/>
<select name="process">
	<option value="crypt">Encrypt</option>
	<option value="decrypt">Decrypt</option>
</select>

<input type="submit" value="Utf&ouml;r" name="submit">
</form>

<b>Crypt:</b> <?php CaesarCipher($message) ?><br/>
<b>Decrypt:</b> <?php CaesarCipher2($message) ?><br/>


</body>
</html>

Re: HTML form tags (+ function) with PHP?

Posted: Tue Apr 20, 2010 5:34 pm
by social_experiment
There is also a logic problem here : You cannot decrypt anything that hasn't been encrypted first. Having a 'decrypt' option before anything is encrypted would be moot. Your code should following a path similar to this :
1.Display textarea.
2.Encrypt user input
3.Show option to decrypt (after encryption)
4.If yes, decrypt text and display.

Note : crypt() is one way hashing so you cannot 'decrypt' it once it's been hashed. From the php manual (sic)
Note: There is no decrypt function, since crypt() uses a one-way algorithm.

Re: HTML form tags (+ function) with PHP?

Posted: Wed Apr 21, 2010 3:14 am
by JAY6390

Code: Select all

<?php

if($_POST['process'] = 'crypt') {
    echo '<b>Crypt:</b>'.CaesarCipher($message).'<br/>';
}else{
    echo '<b>Decrypt:</b>'.CaesarCipher2($message).'<br/>';
}

?>
That is how to display the correct one based on the option selected