Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fFile

posted by mungiu 9 years ago

Please help, i use fFile to remembered upload file in case of validation error, but i can't succes. How i cand aranje the code to work?

This is the sample of code.

$item = new $tabela($id);
					if (fRequest::isPost())
					{
						try
						{

							$item->populate();
							echo "->".fSession::get("pdf");

							//fCore::expose($item);
							fCore::expose($_POST);
							if (isset($column_info['parola']) && fRequest::get('parola') != null)
							{
								$item->setParola(fCryptography::hashPassword(fRequest::get('parola')));
							}

							/*if (isset($column_info['pdf']))
							{
								if ($item->getPdf())
								{
									fSession::set("pdf", '
					<input type="hidden" name="existing-pdf" value="' . $item->encodePdf() . '" />
					<input type="hidden" name="delete-pdf" value="0" />
					Fisier existent: <a href="' . $item->preparePdf(TRUE) . '">' . $item->preparePdf() . '</a>
					<label for="item-delete-pdf">Delete existing pdf</label>
					<input type="checkbox" id="item-delete-pdf" name="delete-pdf" value="1" />');
								}
								else
								{

									// fSession::delete("pdf");

								}
							}

							if (isset($column_info['media']))
							{
								if ($item->getMedia())
								{
									fSession::set("media", '
					<input type="hidden" name="existing-media" value="' . $item->encodeMedia() . '" />
					<input type="hidden" name="delete-media" value="0" />
					Fisier existent: <a href="' . $item->prepareMedia(TRUE) . '">' . $item->prepareMedia() . '</a>
					<label for="item-delete-media">Delete existing uploads</label>
					<input type="checkbox" id="item-delete-media" name="delete-media" value="1" />');
								}
								else
								{

									// fSession::delete("media");

								}
							}*/

							if ($action == "sterge")
							{
								if ($item->delete())
								{
									echo "<div class='validation_succes success'>Succes Delete.</div>";
									//fSession::delete("pdf");
									//fSession::delete("media");
									fURL::redirect("?pagina=texte");
								}
							}
							else
							{
								if ($item->store())
								{
									echo "<div class='validation_succes success'>Succes.</div>";
									//fSession::delete("pdf");
									//fSession::delete("media");
								}
							}
						}

						catch(fValidationException $e)
						{
							echo $e->printMessage();
						}
					}

					// Setare form

					$form = new fForm();
					if ($id != null)
					{
						$form->loadData($item->pullAllValues());
						$form_title = "Editeaza";
					}
					else
					{
						$form_title = "Adauga";
					}

					$i = 0;
					$ajax = self::array_filter_ajax($column_info, "ajax");

					// fCore::expose($categorii);

					$form->set("title", "$form_title $tabela");
					$form->set("name", "form_example");
					$form->set("showDebug", true);
					$form->set("divs", true);
					$form->set("cleanAfterSuccess", false);
					$form->set("submitMessage", null);
					$form->set("showAfterSuccess", true);
					$tabela123 = explode("_", $tabela);
					if (count($tabela123) == 1) $tabela123 = "Categorii_" . strtolower($tabela);
					else $tabela123 = $tabela;
					foreach($column_info as $column => $detalii)
					{ //echo fCore::expose($detalii);
						if (isset($detalii["comment"]) && $detalii["comment"] == "ajax")
						{ //## aici trebe facut pentru categorii
							if ($i === 0)
							{
								$categorii = call_user_func(array(
									$tabela123,
									"getAllParentId"
								) , "Top");
								$categorii1 = $categorii->call("pullValues", "categorie");
								$categorii2 = $categorii->call("pullValues", "categorie");
								$categorii = array_combine($categorii1, $categorii2);
								array_unshift($categorii, "Selecteaza");
							}
							else
							{
								$categorii = array(
									"Selecteaza",
									$item->pullValues($column)
								);
							}
						}

						if (isset($detalii["comment"]) && $detalii["comment"] == "select_no_default_values")
						{
							$categorii = call_user_func(array(
								$tabela123,
								"get_categs_tree"
							));

							// $categorii1 = $categorii->call("pullValues", "categorie");
							// $categorii2 = $categorii->call("pullValues", "categorie");
							// $categorii = array_combine($categorii1, $categorii2);
							// array_unshift($categorii, "Top ...");

							array_unshift($categorii, "Selecteaza");
						}

						$i++;
						switch ($detalii["comment"])
						{
						case text:
							$form->addField("text", $column, ucfirst($column) , false, null);
							break;

						case readonly:
							$form->addField("text", $column, ucfirst($column) , false, null, "readonly='true'");
							break;

						case "date":
							$form->addField("text", $column, ucfirst($column) , false, null, " class='show-weeks dateformat-d-ds-m-ds-Y statusformat-l-cc-sp-d-sp-F-sp-Y'");
							break;

						case "checkbox":
							$form->addText("<input type='hidden' name='" . $column . "' value='0'");
							$form->addField("checkbox", $column, ucfirst($column) , false, null);
							break;

						case "ajax":
							$form->addField("select", $column, ucfirst($column) , false, null, $categorii, "onChange='javascript:Ajax.Request(\\"../getagents.php?method=getXML&param=\\",this.value, \\"&tabela=categorii_" . strtolower($tabela) . "&field=" . $ajax[$i] . "\\", Ajax.Response)';");
							break;

						case "select_no_default_values":
							$form->addField("select", $column, ucfirst($column) , false, null, $categorii);
							break;

						case "select":
							$form->addField("select", $column, ucfirst($column) , false, null, $detalii['valid_values']);
							break;

						case "pdf":
							$form->addField("file", $column, ucfirst($column) , false, null);
							//$form->addText(fSession::get("pdf"));
							if ($item->getPdf()) {
							
							
							$form->addText("<input type='hidden' name='existing-" . $column . "' value='" . $item->preparePdf() . "'");
							
							$form->addText('<input type="hidden" name="delete-pdf" value="0" />
');
							
							$form->addText('Existing pdf: <a href="' . $item->preparePdf(TRUE) . '"> ' . $item->preparePdf() . '</a>
                <label for="item-delete-pdf">Delete existing pdf</label>
                <input type="checkbox" id="item-delete-pdf" name="delete-pdf" value="1" />
');




												}

I would recommend trying to post a smaller section of code. You have included a lot of code, but no real explanation of what isn't working properly.

posted by wbond 9 years ago

Ok, i will try to make smaller and explain what i want to do because kepps me down with my project an it's urgent to resolve this. I start to make a crud with flourish and a class who render form, make it automatic by database schema and field comment.

$item = new $tabela($id);
            //fCore::expose($item);
            if (fRequest::isPost()) {
                try {

                    fCore::expose($item->populate());




                    if ($action == "sterge") {
                        if ($item->delete()) {
                            echo "<div class='validation_succes success'>Succes Delete.</div>";

                            fURL::redirect("?pagina=" . ucfirst($tabela) . "");
                        }
                    } else {
                        if ($item->store()) {
                            echo "<div class='validation_succes success'>Succes.</div>";
                        }
                    }
                } catch (fValidationException $e) {
                    echo $e->printMessage();
                }
            }


... some code ...

                switch ($detalii["comment"]) {




                    case "file":
                        $form->addField("file", $column, ucfirst($column), false, null);
                        //$form->addText(fSession::get("media"));
                        if ($item->getMedia()) {




                            $form->addText("<input type='hidden' name='existing-" . $column . "' value='" . $item->encodeMedia() . "'");

                            $form->addText("<input type='hidden' name='delete-" . $column . "' value='0' />");

                            $form->addText('Existing file: <a href="' . $item->prepareMedia(TRUE) . '"> ' . $item->prepareMedia() . '</a>
                <label for="item-delete-media">Delete existing file</label>
                <input type="checkbox" name="delete-' . $column . '" value="1" />
');
                        }
                        break;



            }

            echo $form->display(ucfirst($action), "btn");
        }

now it's come the problem. for table bannere fo example i configure: fORMFile::configureFileUploadColumn($this, 'media', DOC_ROOT . '/uploads/bannere/');

first when i upload something it's ok that part woth existing file and delete option it's ok even apear a validate issue, but when i push post again file field it empty even post echo existing-media => flourish_temp/sample_copy2.swf delete-media => 0

so every time a row is updated i lost what is in the file field. what should be done. if need other explanation, sk. pls help. tanks

posted by mungiu 9 years ago
#!text/html<form action='' method='post'  name='form_example' id='form_example'  enctype='multipart/form-data'/>
<fieldset><legend>Adauga Tabela</legend><div><label for='denumire'>Denumire: </label>
<input type='text' id='denumire' name='denumire' value=''  /><br />
</div><div><label for='media'>Media: </label>

<input type='file' id='media' name='media'  /><br />
</div><div><input type='hidden' name='existing-media' value='__flourish_temp/99f631e199a0a6d9acbeb1a021f5cb67-d30bhnl_copy2.jpg'</div><div><input type='hidden' name='delete-media' value='0' /></div><div>Existing file: <a href="/proiecte/cd/uploads/tabela/__flourish_temp/99f631e199a0a6d9acbeb1a021f5cb67-d30bhnl_copy2.jpg"> 99f631e199a0a6d9acbeb1a021f5cb67-d30bhnl_copy2.jpg</a>
                <label for="item-delete-media">Delete existing file</label>
                <input type="checkbox" name="delete-media" value="1" />
</div><input type='submit' name='btn' value='Adauga' ></input>
</fieldset></form>
posted by mungiu 9 years ago