Save formdata into database

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
User avatar
Jensensen
Posts: 2995
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: Save formdata into database

Post by Jensensen » Sat 19. Jan 2008, 00:44

Stim wrote:Ok i find it, its stored into phpwcms_formresult > formresult_content.

Can i get data from column formresult_content and show it on webpages somehow?...
Yes you can, but this is not built in!
You need some PHP code additionally, to
read out --> MySQL --> phpwcms_formresult --> formresult_content
and put/wrap it into your html code anyhow.

Don't know how, but for sure it could be done...if at all...by the PHP pro's here on this board...
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.

Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Re: Save formdata into database

Post by Stim » Fri 25. Jan 2008, 01:07

Hi

First of all tank’s for replay but guys, don’t bother this topic anymore. Instead I created new database and try to learning how to send data with form and show result on webpage. Just started to learn and takes little time as newbie.

However what try to say is don’t bother this topic anymore because i ned something other solutions for this project right now and start with learn php and mysql. There must also be some login and register page and also admin system for this project. Members also need their own profile pages, make booking from theirs akount etc.

Lots of thing to do right now but i have litle help and dont need to make all by my self
)-= 1.3.0 user =-(

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Re: Save formdata into database

Post by marcus@localhorst » Fri 25. Jan 2008, 13:49

hi ho,
just in short - the formdata is stored serialized in just one table column.
to use that data, you just need to query this one column and unserialize() it.
you will get an array with all that formvalues for each table row.
it's really easy to work with, if you know how :-)

greetings
marcus

Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Re: Save formdata into database

Post by Stim » Fri 25. Jan 2008, 19:51

marcus@localhorst wrote:to use that data, you just need to query this one column and unserialize() it.
you will get an array with all that formvalues for each table row.
greetings
marcus
Nice to know, Thanks man. I think that "unserialize" probably will came to good use some day for this project.
)-= 1.3.0 user =-(

SaraPerc
Posts: 5
Joined: Mon 19. Sep 2011, 09:08

Re: Save formdata into database

Post by SaraPerc » Mon 19. Sep 2011, 09:50

Hello everyone!

I love phpWCMS and will try to make some contribution to the owners, but have so far no such possibility. So here is my first post, hope this helps somebody!
Regarding to saved form results I have written a code to show the results on the webpage (using the controls to edit, print and delete the records for frontend logged in users and without the controls for non looged in users).
This is an example with all the controls, feel free to play around with the records (insert, edit, delete...): http://sara.hil.ch/cms2/index.php?forms (unfortunately all is in Slovene language, but you will get the idea).
Pressing the link on the right Vsi vnosi (http://sara.hil.ch/cms2/index.php?pregled) will get you to the all saved form results (scroll to the right to see the commands).

Description:
- the form is done by phpwcms content part form, bottom select menu is showing records from another form dinamically.
- All records is written in php on html content part unserializing formresult_content, added command buttons, added printing and filters (filter work by status column and simply adds the status to the tr class name, filter use dynamically records from another phpwcms form. The code is (since I am not a php expert I am sure here the code could use some improvement:

Code: Select all

[PHP]
include 'config/phpwcms/conf.inc.php';

$formvnos = 94;
$formvoznik = 100;
$count = 1;
$countV = 1;
$Filter = $_POST['filter'];


$result = mysql_query("SELECT formresult_id, formresult_content FROM phpwcms_formresult WHERE formresult_pid='$formvnos' ORDER BY formresult_id ASC");
$result2 = mysql_query("SELECT formresult_id FROM phpwcms_formresult WHERE formresult_pid='$formvnos' ORDER BY formresult_id ASC");
$result3 = mysql_query("SELECT formresult_createdate FROM phpwcms_formresult WHERE formresult_pid='$formvnos'");

$result6 = mysql_query("SELECT formresult_id, formresult_content FROM phpwcms_formresult WHERE formresult_pid='$formvoznik' ORDER BY formresult_id ASC");
$result7 = mysql_query("SELECT formresult_id FROM phpwcms_formresult WHERE formresult_pid='$formvoznik'");



if (!$result) {
    die("Query to show fields from table failed");
}



$fields_num = mysql_num_fields($result);
$num = $fields_num-8;

echo "<div><p>
<b><a href=\"index.php?vnos\">Nov vnos</a></b><br \/>
<b><a href=\"index.php?nov-voznik\">Nov voznik</a></b>
</p>



<form action=\"index.php?pregled\" method=\"post\">
<p>Filter: <select name=\"filter\" id=\"filter\">

<option value=\"$Filter\">$Filter<br \/><br \/></option>

<option value=\"Vsi\">Vsi zapisi (Arhiv)</option>
<option value=\"Aktualno\">Vsi razen zaklju&#269;eni (Aktualno)</option>
<optgroup label=\"Status\">
<option value=\"Odprto\">Odprto</option>
<option value=\"Zakljuceno\">Zaklju&#269;eno</option>
</optgroup>
<optgroup label=\"Vozniki\">";

if (!$result6) {
die("Query to show fields from table failed");
}

   while($row6 = mysql_fetch_row($result6)) {
      foreach($row6 as $cell6)

      $serialized_data = $cell6;
      $var = unserialize($serialized_data);
      $varImeV = $var[ImeV];

$varImeSpecial = str_replace(array('Š', 'š', '&#268;', '&#269;', 'Ž', 'ž', ' '), array('S', 's', 'C', 'c', 'Z', 'z', '-'), $varImeV);

echo "<option value=\"$countV-$varImeSpecial\">Voznik $countV: $var[ImeV]</option>";


$countV++; 
}

echo "</optgroup>
</select>

<input type=\"image\" src=\"picture/success.png\" alt=\"Pojdi\"/></p>
</form>


<br \/><br \/>





<form method=\"post\" action=\"index.php?izpis-vseh\" target=\"_blank\">
<input type=\"hidden\" name=\"filter\" value=\"$Filter\" />
 <p><input type=\"submit\" value=\"Tiskaj seznam\"/> </p>
</form><br \/><br \/>






</p></div><br \/>";


echo "<div class=\"tableleft\">";

echo "<table class=\"tableleft\" width=\"870px\" border=\"0px\" cellpadding=\"2px\" cellspacing=\"1px\">";



echo "<tr class=\"header\"><td class=\"id\">ID</td><td class=\"date\">Datum</td><td class=\"ime\">Ime in priimek</td><td class=\"naslov\">Naslov</td><td class=\"kraj\">Kraj</td><td class=\"tel\">Telefon</td><td class=\"kol\">Kol</td><td class=\"cena\">Cena</td><td class=\"opis\">Opis</td><td class=\"opombe\">Opombe</td><td class=\"uredi\">Status</td><td class=\"fid\"> </td><td class=\"uredi\"> </td><td class=\"uredi\"> </td><td class=\"uredi\"> </td></tr>";


// printing table rows

  $z=1;
  while($row = mysql_fetch_row($result))

{   $color = ($z % 2) ? "norm" : "colored";
    echo "<tr class=\"$color\"";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)


$serialized_data = $cell;
$var = unserialize($serialized_data);
$varIme = $var[Ime];
$varNaslov = $var[Naslov];
$varKraj = $var[Kraj];
$varTelefon = $var[Telefon];
$varKol = $var[Kol];
$varCena = $var[Cena];
$varDodatno = $var[Dodatno];
$varOpombe = $var[Opombe];
$varcompleted = $var[completed];




if (!$Filter) {
echo ">";
}

elseif ($varcompleted == $Filter) {
echo ">";
}
elseif ($Filter== 'Vsi') {
echo ">";
}
elseif ($Filter== 'Aktualno' && !($varcompleted == 'Zakljuceno')) {
echo ">";
}


else {
echo " style=\"display:none;\">";
}






echo "<td valign=\"top\">$count</td>";


if ($row3 = mysql_fetch_row($result3)) {
  foreach($row3 as $cell3)

echo "<td valign=\"top\" class=\"date\">";
echo "$cell3";
echo "</td>";
}


echo "<td valign=\"top\">$var[Ime]</td>";
echo "<td valign=\"top\">$var[Naslov]</td>";
echo "<td valign=\"top\">$var[Kraj]</td>";
echo "<td valign=\"top\">$var[Telefon]</td>";
echo "<td valign=\"top\">$var[Kol]</td>";
echo "<td valign=\"top\">$var[Cena]</td>";
echo "<td valign=\"top\">$var[Dodatno]</td>";
echo "<td valign=\"top\">$var[Opombe]</td>";
echo "<td valign=\"top\" class=\"tohide\">";






if ($var[completed] == 'Zakljuceno') {
echo "Zaklju&#269;eno";
}
elseif ($var[completed] == 'Odprto') {
echo "Odprto";
}
else {
echo "$var[completed]";
}




echo "</td>";


  if ($row2 = mysql_fetch_row($result2)) {
  foreach($row2 as $cell2)

echo "<td valign=\"top\" class=\"tohide\">";
echo "$cell2";
echo "</td><td class=\"tohide\"><form action=\"index.php?getid\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />
<input type=\"hidden\" name=\"varcompleted\" value=\"$varcompleted\" />
<input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />
<input type=\"hidden\" name=\"varNaslov\" value=\"$varNaslov\" />

<input type=\"hidden\" name=\"varKraj\" value=\"$varKraj\" />
<input type=\"hidden\" name=\"varTelefon\" value=\"$varTelefon\" />
<input type=\"hidden\" name=\"varKol\" value=\"$varKol\" />
<input type=\"hidden\" name=\"varCena\" value=\"$varCena\" />
<input type=\"hidden\" name=\"varDodatno\" value=\"$varDodatno\" />
<input type=\"hidden\" name=\"varOpombe\" value=\"$varOpombe\" />

<input type=\"image\" src=\"picture/edit.gif\" alt=\"Edit\"/>  </form>
</td>

<td class=\"tohide\"><form action=\"index.php?izpis-narocila\" target=\"_blank\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />
<input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />
<input type=\"hidden\" name=\"varcompleted\" value=\"$varcompleted\" />
<input type=\"hidden\" name=\"varNaslov\" value=\"$varNaslov\" />

<input type=\"hidden\" name=\"varKraj\" value=\"$varKraj\" />
<input type=\"hidden\" name=\"varTelefon\" value=\"$varTelefon\" />
<input type=\"hidden\" name=\"varKol\" value=\"$varKol\" />
<input type=\"hidden\" name=\"varCena\" value=\"$varCena\" />
<input type=\"hidden\" name=\"varDodatno\" value=\"$varDodatno\" />
<input type=\"hidden\" name=\"varOpombe\" value=\"$varOpombe\" />

<input type=\"image\" src=\"picture/print.png\" alt=\"Edit\"/>  </form>
</td>

<td class=\"tohide\">
<form action=\"index.php?delete\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" /><input type=\"hidden\" name=\"varIme\" value=\"$varIme\" /><input type=\"image\" src=\"picture/trash.gif\" alt=\"Brisi\"/> </form>"; 
echo "</td>";
}


    echo "</tr>\n"; 
    $z++;    
    $count++;
}


echo "</table><br \/><br \/></div>";
[/PHP]
- the edit part is done with this code:

Code: Select all

[PHP]
$countV = 1;
$varIme = $_POST['varIme'];
$varNaslov= $_POST['varNaslov'];
$varKraj= $_POST['varKraj'];
$varTelefon= $_POST['varTelefon'];
$varKol= $_POST['varKol'];
$varCena= $_POST['varCena'];
$varDodatno= $_POST['varDodatno'];
$varOpombe= $_POST['varOpombe'];
$varcompleted= $_POST['varcompleted'];
$cell2 = $_POST['cell2'];
$cell3 = $_POST['cell3'];

$result6 = mysql_query("SELECT formresult_id, formresult_content FROM phpwcms_formresult WHERE formresult_pid=100 ORDER BY formresult_id ASC");
$result7 = mysql_query("SELECT formresult_id FROM phpwcms_formresult WHERE formresult_pid=100");

echo "<div class=\"fromright\">
<a href=\"index.php?vnos\">Nov vnos</a><br \/>
<a href=\"index.php?pregled\">Vsi vnosi</a><br \/><br \/>

<form action=\"index.php?izpis-narocila\" target=\"_blank\" method=\"post\">
<input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />
<input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />
<input type=\"hidden\" name=\"varcompleted\" value=\"$varcompleted\" /><input type=\"hidden\" name=\"varNaslov\" value=\"$varNaslov\" /><input type=\"hidden\" name=\"varKraj\" value=\"$varKraj\" /><input type=\"hidden\" name=\"varTelefon\" value=\"$varTelefon\" /><input type=\"hidden\" name=\"varKol\" value=\"$varKol\" />
<input type=\"hidden\" name=\"varCena\" value=\"$varCena\" /><input type=\"hidden\" name=\"varDodatno\" value=\"$varDodatno\" /><input type=\"hidden\" name=\"varOpombe\" value=\"$varOpombe\" />
Tiskaj: <input type=\"image\" src=\"picture/print.png\" alt=\"Edit\"/>  </form>

<form action=\"index.php?delete\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" /><input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />Odstrani: <input type=\"image\" src=\"picture/trash.gif\" alt=\"Brisi\"/> </form>

</div>";

echo "<form  action=\"index.php?update\" method=\"post\">

<input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />

<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"504px\">


<tr><td></td>
<td>Naro&#269;ilo: $cell2 <br \/><span class=\"formtext\">($cell3)</span></td>

<td valign=\"top\">Status: <select name=\"completed\" id=\"completed\">
<option value=\"$varcompleted\">";


if ($varcompleted == 'Zakljuceno') {
echo "Zaklju&#269;eno";
}
elseif ($varcompleted == 'Odprto') {
echo "Odprto";
}
else {
echo "$varcompleted";
}

echo "</option>

<option value=\"Odprto\">Odprto</option>
<option value=\"Zakljuceno\">Zaklju&#269;eno</option>
<optgroup label=\"Vozniki\">";

if (!$result6) {
die("Query to show fields from table failed");
}

   while($row6 = mysql_fetch_row($result6)) {
      foreach($row6 as $cell6)

      $serialized_data = $cell6;
      $var = unserialize($serialized_data);
      $varImeV = $var[ImeV];

$varImeSpecial = str_replace(array('Š', 'š', '&#268;', '&#269;', 'Ž', 'ž', ' '), array('S', 's', 'C', 'c', 'Z', 'z', '-'), $varImeV);

echo "<option value=\"$countV-$varImeSpecial\">Voznik $countV: $var[ImeV]</option>";





$countV++; 
}

echo "</optgroup></select>




</td></tr>



<tr><td width=\"45\"></td>
<td width=\"139\">Ime in priimek:* </td>

<td width=\"320\"><input type=\"text\" name=\"Imex\" id=\"Imex\" value=\"$varIme\" class=\"inputField\" \/> 
<span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td>Naslov:* </td>
<td><input type=\"text\" name=\"Naslov\" id=\"Naslov\" value=\"$varNaslov\" class=\"inputField\" \/> <span class=\"formerror\"></span></td></tr>
<tr><td></td>
<td>Kraj:* </td>
<td><input type=\"text\" name=\"Kraj\" id=\"Kraj\" value=\"$varKraj\" class=\"inputField\" \/> <span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td>Telefon:*  </td>

<td><input type=\"text\" name=\"Telefon\" id=\"Telefon\" value=\"$varTelefon\" class=\"inputField\" \/> <br \/>
<span class=\"formtext\">(Po potrebi dopišite kontaktno osebo)</span><span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td></td>
<td> </td></tr>

<tr><td></td>
<td>Koli&#269;ina:* </td>
<td><input type=\"text\" name=\"Kol\" id=\"Kol\" value=\"$varKol\" class=\"inputFieldNum\" \/><span class=\"formtext\"> palet(a)</span> <span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td>Cena:* </td>
<td><input type=\"text\" name=\"Cena\" id=\"Cena\" value=\"$varCena\" class=\"inputFieldNum\" \/><span class=\"formtext\"> EUR</span> <span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td>Dodatni opis:  <br \/>
<span class=\"formtext\">(Vnesite željene dimenzije drv)</span></td>
<td><textarea name=\"Dodatno\" id=\"Dodatno\" cols=\"20\" rows=\"3\" class=\"inputFieldText\">$varDodatno</textarea> <span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td>Opombe:  <br \/>
<span class=\"formtext\">(Vnesite datum dostave, prevoznika...)</span></td>
<td><textarea name=\"Opombe\" id=\"Opombe\" cols=\"20\" rows=\"3\" class=\"inputFieldText\">$varOpombe</textarea> <span class=\"formerror\"></span></td></tr>

<tr><td></td>
<td></td>
<td><br><input type=\"submit\" value=\"Shrani\"  name=\"submitIt\" id=\"submitIt\"></td></tr>

</table>
</form>";
[/PHP]
- delete command:

Code: Select all

[PHP]
$varIme = $_POST['varIme'];
$cell2 = $_POST['cell2'];

$result3=mysql_query("DELETE FROM phpwcms_formresult WHERE formresult_id= $cell2");


echo "<p>Naro&#269;ilo ID: ";
echo "$cell2";
echo " za ";
echo "$varIme";
echo " je izbrisano!</p>";
[/PHP]

<p><br /><a href="index.php?pregled">Vsi vnosi</a></p>
- update after edit:

Code: Select all

[PHP]

include 'config/phpwcms/conf.inc.php';

$cell2 = $_POST['cell2'];
$cell3 = $_POST['cell3'];
$varcompleted = $_POST['completed'];
$varIme = $_POST['Imex'];
$varNaslov= $_POST['Naslov'];
$varKraj= $_POST['Kraj'];
$varTelefon= $_POST['Telefon'];
$varKol= $_POST['Kol'];
$varCena= $_POST['Cena'];
$varDodatno= $_POST['Dodatno'];
$varOpombe= $_POST['Opombe'];

$var["Ime"] = $varIme;
$var["Naslov"] = $varNaslov;
$var["Kraj"] = $varKraj;
$var["Telefon"] = $varTelefon;
$var["Kol"] = $varKol;
$var["Cena"] = $varCena;
$var["Dodatno"] = $varDodatno;
$var["Opombe"] = $varOpombe;
$var["completed"] = $varcompleted;

$serialized = serialize($var);





echo "<p>Naro&#269;ilo ID: ";
echo "$cell2 <span class=\"formtext\"> ($cell3)</span>";
echo " za ";
echo "$varIme";
echo " je posodobljeno!</p>";




echo "<div class=\"fromright\">
<a href=\"index.php?vnos\">Nov vnos</a><br \/>
<a href=\"index.php?pregled\">Vsi vnosi</a><br \/><br \/>



<form action=\"index.php?getid\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />
<input type=\"hidden\" name=\"varcompleted\" value=\"$varcompleted\" />
<input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />
<input type=\"hidden\" name=\"varNaslov\" value=\"$varNaslov\" />

<input type=\"hidden\" name=\"varKraj\" value=\"$varKraj\" />
<input type=\"hidden\" name=\"varTelefon\" value=\"$varTelefon\" />
<input type=\"hidden\" name=\"varKol\" value=\"$varKol\" />
<input type=\"hidden\" name=\"varCena\" value=\"$varCena\" />
<input type=\"hidden\" name=\"varDodatno\" value=\"$varDodatno\" />
<input type=\"hidden\" name=\"varOpombe\" value=\"$varOpombe\" />
Uredi: 
<input type=\"image\" src=\"picture/edit.gif\" alt=\"Edit\"/></form>

<form action=\"index.php?izpis-narocila\" target=\"_blank\" method=\"post\">
<input type=\"hidden\" name=\"cell2\" value=\"$cell2\" />
<input type=\"hidden\" name=\"cell3\" value=\"$cell3\" />
<input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />
<input type=\"hidden\" name=\"varcompleted\" value=\"$varcompleted\" /><input type=\"hidden\" name=\"varNaslov\" value=\"$varNaslov\" /><input type=\"hidden\" name=\"varKraj\" value=\"$varKraj\" /><input type=\"hidden\" name=\"varTelefon\" value=\"$varTelefon\" /><input type=\"hidden\" name=\"varKol\" value=\"$varKol\" />
<input type=\"hidden\" name=\"varCena\" value=\"$varCena\" /><input type=\"hidden\" name=\"varDodatno\" value=\"$varDodatno\" /><input type=\"hidden\" name=\"varOpombe\" value=\"$varOpombe\" />Tiskaj: 
<input type=\"image\" src=\"picture/print.png\" alt=\"Edit\"/></form>

<form action=\"index.php?delete\" method=\"post\"><input type=\"hidden\" name=\"cell2\" value=\"$cell2\" /><input type=\"hidden\" name=\"varIme\" value=\"$varIme\" />Odstrani: <input type=\"image\" src=\"picture/trash.gif\" alt=\"Brisi\"/></form>


</div>";


echo "<br \/><div class=\"tablerow\">";
echo "<table class=\"tableleft\" width=\"420px\" border=\"0px\" cellpadding=\"2px\" cellspacing=\"1px\"><tr>

<td valign=\"top\" width=\"120px\">Ime in priimek: </td>
<td valign=\"top\"><b>$varIme</b></td>
</tr><tr>
<td valign=\"top\">Naslov: </td>
<td valign=\"top\">$varNaslov</td>
</tr><tr>
<td valign=\"top\"> </td>
<td valign=\"top\">$varKraj</td>
</tr><tr>
<td valign=\"top\">Telefon: </td>
<td valign=\"top\">$varTelefon</td>
</tr><tr>
<td valign=\"top\">Kol: </td>
<td valign=\"top\">$varKol palet(a)</td>
</tr><tr>
<td valign=\"top\">Cena: </td>
<td valign=\"top\">$varCena EUR</td>
</tr><tr>
<td valign=\"top\">Dodatno: </td>
<td valign=\"top\">$varDodatno</td>
</tr><tr>
<td valign=\"top\">Opombe: </td>
<td valign=\"top\">$varOpombe</td>
</tr></table>";

echo "</div>";

mysql_query("UPDATE phpwcms_formresult SET formresult_content = '$serialized' WHERE formresult_id= '$cell2'");
[/PHP]
- and the form template itself that contains select menu with records from another form (I have put the select menu as var on the form, but written manually the code for the select menu):

Code: Select all

<div class="fromright">
<a href="index.php?pregled">Vsi vnosi</a>
</div>

<table border="0" cellspacing="0" cellpadding="0" width="504">

<tr><td width="45"></td>
<td width="139">{LABEL:Ime}* </td>
<td width="320">{Ime} <span class="formerror">{ERROR:Ime}</span></td></tr>

<tr><td width="45"></td>
<td width="139">{LABEL:Naslov}* </td>
<td width="320">{Naslov} <span class="formerror">{ERROR:Naslov}</span></td></tr>
<tr><td width="45"></td>
<td width="139">{LABEL:Kraj}* </td>
<td width="320">{Kraj} <span class="formerror">{ERROR:Kraj}</span></td></tr>

<tr><td></td>
<td>{LABEL:Telefon}*  </td>
<td>{Telefon} <br />
<span class="formtext">(Po potrebi dopišite kontaktno osebo)</span><span class="formerror">{ERROR:Telefon}</span></td></tr>

<tr><td width="45"></td>
<td></td>
<td>&nbsp;</td></tr>

<tr><td width="45"></td>
<td>{LABEL:Kol}* </td>
<td>{Kol}<span class="formtext"> palet(a)</span> <span class="formerror">{ERROR:Kol}</span></td></tr>

<tr><td width="45"></td>
<td>{LABEL:Cena}* </td>
<td>{Cena}<span class="formtext"> EUR</span> <span class="formerror">{ERROR:Cena}</span></td></tr>

<tr><td width="45"></td>
<td width="139">{LABEL:Dodatno}  <br />
<span class="formtext">(Vnesite željene dimenzije drv)</span></td>
<td width="320">{Dodatno} <span class="formerror">{ERROR:Dodatno}</span></td></tr>

<tr><td width="45"></td>
<td width="139">{LABEL:Opombe}  <br />
<span class="formtext">(Vnesite datum dostave, ...)</span></td>
<td width="320">{Opombe} <span class="formerror">{ERROR:Opombe}</span></td></tr>

<tr><td width="45"></td>
<td width="139">Dolo&#269;ite voznika: <br /><span class="formtext">(Ali pustite 'Odprto')</span></td>
<td width="320">
[PHP]
echo "<select name=\"completed\" id=\"completed\"><option value=\"Odprto\">Odprto</option>"; 
$countV = 1; 
$result6 = mysql_query("SELECT formresult_id, formresult_content FROM phpwcms_formresult WHERE formresult_pid=100 ORDER BY formresult_id ASC"); 
if (!$result6) { die("Query to show fields from table failed"); }   
while($row6 = mysql_fetch_row($result6)) { 
foreach($row6 as $cell6) 
$serialized_data = $cell6; 
$var = unserialize($serialized_data); $varImeV = $var[ImeV]; $varImeSpecial = str_replace(array('Š', 'š', '&#268;', '&#269;', 'Ž', 'ž', ' '), array('S', 's', 'C', 'c', 'Z', 'z', '-'), $varImeV); 
echo "<option value=\"$countV-$varImeSpecial\">Voznik $countV: $var[ImeV]</option>"; 
$countV++; 
}
echo "</select>";
[/PHP]


</td></tr>


<tr><td></td>
<td></td>
<td><br />{submitIt} {resetIt}</td></tr>
</table>
This form is to archive orders. The orders have status Odprto (Opened), Zakljuceno (Closed) and the drivers that deliver the goods to the customer. The other form contains records for the drivers (put also on enter form, edit form and filters).
The php for the drivers form is the same as for the orders form (changed id of the form and of course the variables).

This is a code to display all serialized stored records (to get form id in order to make the php work):

Code: Select all

[PHP]
include 'config/phpwcms/conf.inc.php';
$table = 'phpwcms_formresult';
$count = 1;

$result = mysql_query("SELECT * FROM phpwcms_formresult ORDER BY formresult_id ASC");

if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<div class=\"tableleft\">";
echo "<table border='0'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";

// printing table rows
  $z=1;
  while($row = mysql_fetch_row($result))

{   $color = ($z % 2) ? "norm" : "colored";
    echo "<tr class=\"$color\">";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)

echo "<td valign=\"top\">$cell</td>";
echo "</tr>\n"; 
    $z++;    
    $count++;
}
echo "</table><br \/><br \/></div>";
[/PHP]
All table records have the possibility to print the table (using filters). This is done on a separate page with its own template and css, but only putting content part alias to the page (from where all records are shown). Css for printouts:

Code: Select all

body {
	font-family: Arial, Verdana, Helvetica, sans-serif;
	font-size: 13px;
	background-color: none;
text-decoration: none;
margin-top: 10px; margin-left: 0px; margin-right: 0px;margin-bottom: 20px;
}
div, input, td.tohide, td.fid, td.uredi   {display: none;}
div.tablerow, div.tableleft {display: block; margin-left: 4px; }
table.tableleft {width: 660px !important;}
table {border-top: 1px solid black; border-right: 1px solid black;}
table td {border-left: 1px solid black; border-bottom: 1px solid black;}
And of course css for the form, table...:

Code: Select all

div.tableleft { float: left;
top: 0px; left: 0px; height: auto; width: auto;
background: none; border: none;
overflow: hidden; visibility: visible;
}

table.tableleft tr, table.tableright tr { font-size: 11px; }
div.tablerow table.tableleft tr { font-size: 13px; }
table.tableleft tr.colored {background-color: #ffffff;}
div.tableleft, div.tablerow {margin-left: 0px;}
tr.header td {font-weight: bold; font-size: 13px;}
td.id {width: 13px;}
td.ime {width: 100px;}
td.naslov {width: 70px;}
td.kraj {width: 60px;}
td.tel {width: 60px;}
td.kol {width: 15px;}
td.cena {width: 30px;}
td.uredi {width: 12px;}
td.date {width: 70px;}
td.opis {width: 100px;}
td.opombe {width: 100px;}


div.fromright { position: relative;
top: 36px; left: 570px; height: 1px; width: 120px;
background: none; border: none;
overflow: visible; visibility: visible; font-weight: bold;}


.formtext {	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #cccccc;}
.formerror {	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #FF9900;}
.inputField, .inputFieldText {width: 240px; margin: 2px;}
.inputFieldText {margin-top: 3px; height: 90px;}
.inputFieldNum {width: 40px; margin: 2px;}

That's it!
This image shows a live example: http://sara.hil.ch/cms2/picture/live.jpg
Note that the way this example is displayed it should be protected with frontend login (forms contain no anti spam, commands are available). With out commands you can show lists on the webpage.

Like I said, I know that the code could use some improvement, but it works :)

And the question now:
How to enable sorting by serialized values (formresult_content) for the column names?
Hope someone can give me some guidelines!

Best regards,
Sara

User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Re: Save formdata into database

Post by marcus@localhorst » Mon 19. Sep 2011, 21:59

And the question now:
How to enable sorting by serialized values (formresult_content) for the column names?
Hope someone can give me some guidelines!
you can sort via array sort functions - check this: http://www.php.net/manual/de/function.a ... tisort.php

btw. even if your script is supposed to be in a protected area you should check your $_POST input vars.
Search in PHPwcms sourcecode for $_POST vars an see how they are filtered, before sending to the Database!
And if you study the sourcecode, check out the PHPWCMS database wrapper function for simplified DB queries, like _dbQuery(), _dbGet(), _dbUpdate etc.

cheers
marcus

SaraPerc
Posts: 5
Joined: Mon 19. Sep 2011, 09:08

Re: Save formdata into database

Post by SaraPerc » Wed 21. Sep 2011, 08:49

Hi Marcus!

Thanks for the advice. I have never look at this this way. Looks like I have a lot more studying to do :).
But hey, with each new phpwcms feature you give us and each time I learn something new my options not only multiply but are potentiated.
Will get to this as soon as I have some free time and post the finished code back to this forum.

Best regards,
Sara

Post Reply