Fly Posted March 25, 2007 Share Posted March 25, 2007 Hi folks. I want to write a poll script. In add.php, the page where people can add polls, i want make the input text areas dynahmic, like phpBB with button "Add answer" and then to reload the page with new text area with place for other answer. Thanks in advance. Mitko Kostov/ Quote Link to comment Share on other sites More sharing options...
papaface Posted March 25, 2007 Share Posted March 25, 2007 Do it yourself! We are not here to write your scripts. What I can tell you is that you will need a database. When you have some code post it back and we'll help. Quote Link to comment Share on other sites More sharing options...
Fly Posted March 25, 2007 Author Share Posted March 25, 2007 You didn't understand me. I have some skills in PHP/MySQL. But i cannot create the text areas dynamic. <?php if(isset($_GET['count'])){ $count = $_GET['count']; $count = $count+1; } else{ $count = 1; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <table cellpadding="0" cellspacing="0" border="0"> <?php for($i=0; $i<$count; $i++) { echo "<tr>"; echo "<td>"; echo "<input type=\"text\" value=\"\" size=\"28\"/>"; echo "</td>"; echo "</tr>"; } ?> <tr> <td><a href="<?php echo "".$_SERVER['PHP_SELF']."?count=$count"."" ?>">Add</a></td> </tr> </table> </body> </html> Something like that, but after clicking "Add" the values of the text area ( answers ) is being deleted. How can i do it with submit button to add more text areas for answers ? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted March 25, 2007 Share Posted March 25, 2007 are you after something like this? echo <<<html <form action="{$_SERVER['REQUEST_URI']}" method="POST"> html; $q = $_POST['q']; $i = 1; foreach($q as $data){ echo "Answer {$i}: <input type='text' name='q[{$i}]' value='{$data}'><br>"; $i++; } if(isset($_POST['add_text_box'])){ echo "Answer {$i}: <input type='text' name='q[{$i}]' value=''><br>"; } echo <<<html <br> <input type="submit" name="add_text_box" value="add answer"> </form> html; Quote Link to comment Share on other sites More sharing options...
Fly Posted March 25, 2007 Author Share Posted March 25, 2007 Something like that ... but i don't know how to place another submit button to proccess the form to the other page ... <?php //Params //GET Count if(isset($_GET['count'])){ $count = $_GET['count']; $count = $count+1; } else{ $count = 1; } //SET CURRENT ACTION if(!isset($_GET['action'])){ $action = "list"; } else { $action = $_GET['action']; } if($action == "add"){ for($i=0; $i<$count; $i++) { $s_value[$i] = ($_POST['s_value'.$i]); $i_value[$i] = $s_value[$i]; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Poll System</title> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <form method="POST" action="<?php echo "".$_SERVER['PHP_SELF']."?action=add&count=$count"?>" name="pubform" enctype="multipart/form-data"> <table cellpadding="0" cellspacing="0" border="0"> <?php for($i=0; $i<$count; $i++) { ?> <tr> <td><input type="text" name="<?php echo "s_value".$i.""; ?>" id="<?php echo "s_value".$i.""; ?>" value="<?php echo "".$i_value[$i]."" ?>" size="28"/></td> </tr> <?php } ?> <tr> <td><input type="submit" name="submit" id="submit" value="Add" size="15"/></td> </tr> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted March 26, 2007 Share Posted March 26, 2007 You could do this with JavaScript and save the time and hassle of reloading the page. There is some good example code at the below address: http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/ Change that code too input textboxes and you should be good to go. Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted March 26, 2007 Share Posted March 26, 2007 Here's another example that uses a slightly different method, but produces the same result: http://www.mredkj.com/tutorials/tableaddrow.html Good luck! Quote Link to comment 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.