Jump to content

Help with poll system


Fly

Recommended Posts

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/

Link to comment
Share on other sites

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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.