I generate a form based on some data I get from a database.
Here is my constructor:
php_core.php
<?php
echo "<style>";
echo ".spoll{ -webkit-box-sizing: border-box;";
echo "-moz-box-sizing: border-box;";
echo "box-sizing: border-box;";
echo "padding: 10px;";
echo "padding-top: 5px;";
echo "}";
echo "</style>";
//DISPLAY FUNCTION
function display($x){
require("db_conx.php");
$sql = "SELECT * FROM polls WHERE id='$x' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$poll_id = $row['id'];
$topic = $row['topic'];
$startdate = $row['startdate'];
$stopdate = $row['stopdate'];
$active = $row['active'];
$type = $row['type'];
$title = $row['title'];
$pwidth = $row['pwidth'];
$borcolor = $row['borcolor'];
$borwidth = $row['borwidth'];
$fcolor = $row['fcolor'];
$bfcol = $row['bfcol'];
$bg = $row['bg'];
$borrad = $row['borrad'];
$abars = $row['abars'];
$bcol = $row['bcol'];
$brad = $row['brad'];
}
//DISPLAY THE POLL
$aquery = "SELECT * FROM answers WHERE parent='$poll_id'";
$result = mysqli_query($db_conx, $aquery);
echo '<div class="spoll" style="width: '.$pwidth.'px; border: '.$borwidth.'px solid '.$borcolor.'; border-radius: '.$borrad.'px; color: '.$fcolor.'; background-color: '.$bg.';">';
echo '<p><b>'.$title.'</b></p>';
echo '<p style="font-size: 13px;">'.$topic.'</p>';
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
// SELECT ANSWERS
if($type == 'single'){
while ($usersRow = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo '<input type="radio" name="rad" value="'.$usersRow['id'].'"/>'.$usersRow['content'].'<br><br>';
}
} else {
$i = 0;
while ($usersRow = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo '<input type="checkbox" name="check[]" value="'.$usersRow['id'].'"/>'.$usersRow['content'].'<br><br>';
$i++;
}
}
//echo '<button style="border-radius: '.$brad.'px; border: none; padding: 10px; width: 100%; margin: auto; background-color: '.$bcol.'; color:'.$bfcol.'" value="VOTE" onclick="vote('.$poll_id.');"><b>VOTE</b></button>';
echo '<input type="submit" value="Vote" style="border-radius: '.$brad.'px; border: none; padding: 10px; width: 100%; margin: auto; background-color: '.$bcol.'; color:'.$bfcol.'">';
echo '</form>';
echo '</div>';
}
// END OF THE DISPLAY FUNCTION
?>
Here is how I display the form:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include("php_includes/php_core.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php display('15'); ?>
<span id="status"></span>
<?php
if(isset($_POST['submit'])){
echo "Posted!";
?>
</body>
</html>
I don't know why, but it won't submit the values! The function outputs the form correctly, I've checked it by viewing the page source. I have no idea why it does not work, so I need your help. I've been modifying the script again and again, no result.
An additional(optional) question about this script: Do you have any idea about how I can submit this form using AJAX without any additional HTML tags and refresh the function output without reloading the page? I found some ways, but I must wrap the function inside a div and I need to keep the output structure and method, so I'm out of ideas.