Jump to content

Help with poll system


Fly

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/44213-help-with-poll-system/#findComment-214734
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/44213-help-with-poll-system/#findComment-214744
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/44213-help-with-poll-system/#findComment-214948
Share on other sites

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.

 

:)

Link to comment
https://forums.phpfreaks.com/topic/44213-help-with-poll-system/#findComment-215133
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.