Handling Form Data

HI.

I have a working class to scan a text, separate each word, and analyse each one individually. My next step is to create a form for users to submit their text to be analysed and outputted by my PHP class. I have successfully created the form and linked to my PHP class.
Here is my form:

<form name="postagger" action="postagger.php" method="POST"> <textarea name="Text to tag" rows="10" cols="60">Enter your text to tag here</textarea><br /> <input type="submit" /> </form>

postagger.php uses a print function to output data after the input has been parsed. I’m having trouble using the inputted form text with the print function. The relevant part of postagger.php looks like this:
[php]<?php
// little helper function to print the results
function printTag($tags) {
foreach($tags as $t) {
echo ‘’;
echo $t[‘token’] . " ";
echo ‘
’;
}
echo “\r\n”;
}

$tagger = new PosTagger(‘lexicon.txt’);
?>[/php]
The print function ^^.
[php]<?php
//Check whether the form has been submitted
if (array_key_exists(‘check_submit’, $_POST)) {
$tags = $tagger->tag {$_POST[‘Text to tag’]};
printTag($tags);

} else {
echo ‘Something went wrong!’;
}
?>[/php]
How I’m currently trying to process the form input text^^ which is not working, as I’m getting “Something went wrong” output!
Any help would be much appreciated. Thanks (Hope I explained clearly enough)

I would suggest finding a nice tutorial on how to do a Form, but I’ll just point out that you are injecting OOP style (not that it’s OOP) into the mix and doing it wrong:

You have:
[php]$tags = $tagger->tag {$_POST[‘Text to tag’]};[/php]

It Should be something like this:
[php]$tags = $tagger->tag($_POST[‘textToTag’]); [/php]

My suggestion get procedural style down pat first then go onto OOP style and studying up on design patterns, I’m still probably considered a noob to those who know OOP down pat.

Sponsor our Newsletter | Privacy Policy | Terms of Service