Jump to content

Form Changing Changing Textarea


garyblackpool

Recommended Posts

The sever which i am using runs on php5 so i think the problam is with the syntax. I keep on getting Fatal error: Function name must be a string. Could you please help cos been searching but have not been able to find anyting thanks.

<form method="post" action="display_input.php"><p><strong> Text Field</strong><br><textarea name="text" cols=45 rows=5 wrap=virtual></textarea></p><p><strong>String Functions</strong></br><input type="radio" name="func" value="md5" checked> get md5<br><input type="radio" name="func" value="strlen" checked> length of string<br><input type="radio" name="func" value="strrev" checked>reverse string<br><input type="radio" name="func" value="strtoupper" string uppercase<br><input type="radio" name="func" value="strtolower" checked>string lowercase3<br><input type="radio" name="func" value="ucwords" checked>first letter capital<br></p><p><input type="submit" name="submit" value="do Something with the String"><p></form>

And this is the other file

<?$func = $POST_["func"];$text1 = $POST_["text1"];$result = $func($text1); ?><html><head<title> Generic Input Results</title></head><body><? echo "$result"; ?><p><a href="generic_form.html">Go again!</a><p></body><html>

Thanks for any help

Link to comment
Share on other sites

I'll be surprised if your setup will work. $_POST["func"] will be parsed as a string, not a function reference. You may need to add an eval() statement in there. The following works, for example:

<?php	$str = 'hello';	$func="strlen";	$L= eval("return $func($str);");	echo $L;?>

Link to comment
Share on other sites

This will work also:

$str = 'hello';$func="strlen";echo $func($str);

PHP's weird like that. It also works to just use the function reference:

<?php$str = 'hello';$func="strlen";echo $func($str);$func = strlen;echo $func($str);?>

both of those will run strlen.

Link to comment
Share on other sites

Naah. You can learn a lot from a PHP4 book. Most ver. 5 features that you'll need you can get from the online manual. You've seen that, right? http://www.php.net/manual/en/index.phpI use it all the time.
Yes I have looked through the manual but it does seem to be rather confusing. Still have not figured how to formate the form on the results page. cheerz
Link to comment
Share on other sites

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...