sasori Posted July 28, 2008 Share Posted July 28, 2008 (noob here) am trying to make a seperate function for an input form and a submit button form then i wanna use the both function in an index file and it should output whatever i input inside the form here's the code of my index file <?php require("includes/formfunctions.inc.php"); inputform($input); submitbutton($input); if($_GET['$input'] == '$submit') { echo $input; } ?> at the bottom are the 2 functions saved as formfunctions.inc.php here's the submit button function code <?php function submitbutton() { echo "<form>"; echo "<input type='submit' name='$submit' value='send'>"; echo "</form>"; return $input; } ?> here's the input form function code <?php function inputform($input) { echo "<form>"; echo "<input type='text' name='$input' size='10'>"; echo "</form>"; return $input; } ?> they look good..but when i input a word in the input form and click send.nothing happens ..will somebody help me with the logic please Link to comment https://forums.phpfreaks.com/topic/116941-coding-help/ Share on other sites More sharing options...
d.shankar Posted July 28, 2008 Share Posted July 28, 2008 Have you checked out the require path ?? Link to comment https://forums.phpfreaks.com/topic/116941-coding-help/#findComment-601360 Share on other sites More sharing options...
JasonLewis Posted July 28, 2008 Share Posted July 28, 2008 You've set it up quite strange... Your passing a variable $input to both functions, yet only one of the functions accepts a parameter. Also, you have two form tags, both with no action or method attribute and in your code you're using $_GET. Try something like this, all in the one file: <?php //First we will check if the submit button has been hit if(isset($_POST['submit'])){ //Yes, it's been pressed. echo $_POST['text']; //lets echo out what they wrote in the field called text }else{ //Well, no submit button was pressed. //So lets show the form. //The $_SERVER['REQUEST_URI'] just gets the link to the page they are on. echo <<<html <form action="{$_SERVER['REQUEST_URI']}" method="post"> <input type="text" name="text" id="text"><br /> <input type="submit" name="submit" id="submit"> </form> html; } ?> Link to comment https://forums.phpfreaks.com/topic/116941-coding-help/#findComment-601366 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 Its really quite unclear what your trying to do. You functions use variables which are not declared, they return values you never use, then your calling code does much the same. Also, your submit buitton must be within the same <form> in order to send the actual form. Lets try a simpler example. <?php function form() { echo "<form>"; echo " <input type='text' name='input' size='10'>"; echo " <input type='submit' name='submit' value='send'>"; echo "</form>"; } if (isset($_GET['submit'])) { echo $_GET['input']; } else { form(); } ?> Link to comment https://forums.phpfreaks.com/topic/116941-coding-help/#findComment-601367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.