Mike088 Posted October 10, 2008 Share Posted October 10, 2008 Hi all I'll start of by saying I am really new to PHP . I am trying to create a form in which a user submits a word then it outputs a list of words which are generated from a PHP class. How would I go about doing this lol? Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/ Share on other sites More sharing options...
genericnumber1 Posted October 10, 2008 Share Posted October 10, 2008 There are a lot of results for php form handling on google. What do you mean it outputs a list of words from a class? Does the input have to do with how these words are generated? Are the words hard coded into a class? from a database? Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661643 Share on other sites More sharing options...
.josh Posted October 10, 2008 Share Posted October 10, 2008 I wouldn't really recommend diving into classes if you don't know how to do basic form submission. But regardless, you're going to have to be more specific about how this class generates this list of words, and how the submitted word is supposed to interact. In other words, you need to write out in plain english what it is you want to happen, before you can go about coding it. But even then, don't just tell us what you want. We aren't here to write code for you. Write out what you want in plain english, break it down step by step, research how to do each step, if you get stuck on actual code, post the code. Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661644 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Share Posted October 10, 2008 quick 1 page example for you......... save the page as example.php try it ...... <center><h3>Please type >>css<< or >>php<< or >>html<<</h3></center> <br><br> <?php if(isset($_POST['submit'])){ $words=(trim($_POST['words'])); switch ($words){ case(php); echo " <center><h1>php is the best!</h1></center>"; break; case(html); echo "<center><h1>html is grate fun!</h1></center>"; break; case(css); echo"<center><h1>css is so good fun!</h1></center>"; break; } } ?> <center> <form method="POST" action="<?php $_SEVER['PHP_SELF']?>"> Type a word please <br> <input type="text" name="words"> <br><br> <input type="submit" name="submit" value="post the famous word!"> </form> </center> Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661656 Share on other sites More sharing options...
Mike088 Posted October 10, 2008 Author Share Posted October 10, 2008 Thanks for the replies. I have a basic script as follows: <form action="index.php" method="post"> Enter Your Word: <input type="text" name="word" /> <input type="submit" value="Submit" /> </form> <?php echo $_POST["word"]; ?> As you can see I have it just outputting the word that was input. I have a PHP class that generates common misspellings from a word (in this case I want it to be the word the user is inputting to my form). I have no idea on how to get the interaction between the input word and the class. The class I am wanting to use is http://web-professor.net/scripts/typo/cTypoGenerator.txt. Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661686 Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 what about the example shown... Example Usage: ----------------------------------------------------------- <?php if(isset($_POST['submit'])) { $word = trim($_POST["word"]); $typos = array(); $typos = cTypoGenerator::getAllTypos( $word ); print_r( $typos ); } ?> i have also checked if post submit is set so make sure you add name="submit" to your submit button Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661697 Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 should probably add that you will need to include the file with your class in above that snippet of code and instead of using print_r you might want to use something like this to generate a list foreach($typos as $word) { echo $word . "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661701 Share on other sites More sharing options...
redarrow Posted October 10, 2008 Share Posted October 10, 2008 Sorry that class no good for me, I slip with my hands on the keys all the time ill have a constant error lol....................................................... add a <?php include("script_name.php");?> to the posted below example DONT FORGET THE DONATION PAGE OFF THIS FORUM......... <?php include("script_name.php"); if(isset($_POST['submit'])) { $word = trim($_POST["word"]); $typos = array(); $typos = cTypoGenerator::getAllTypos( $word ); foreach($typos as $word) { echo $word . "<br />"; } } <form action="index.php" method="post"> Enter Your Word: <input type="text" name="word" /> <input type="submit" value="Submit" /> </form> ?> Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661702 Share on other sites More sharing options...
Mike088 Posted October 10, 2008 Author Share Posted October 10, 2008 Thank you all very much for the help (/answers lol) Quote Link to comment https://forums.phpfreaks.com/topic/127806-solved-newby-help-with-form/#findComment-661718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.