Quote
Until that part of Documentation is completed, simply look @ examples in the various implementations we provided. There are like 10 bundled Infusions that use that system currently.
- by Falk
openside("");
echo openform("opret_aktivitet","POST",FUSION_SELF."?section=ny_aktivitet",array("class" => "m-t-20"));
echo "<div class='row'>\n";
echo "<div class='col-xs-12 col-sm-8'>\n";
echo form_hidden("func","opret");
echo form_text("navn",utf8_encode("AKTIVITET"),"",array(
'placeholder' => utf8_encode('Angiv navn på aktivitet'),
'required' => TRUE,
'width' => '250px',
'max_length' => 200,
'error_text' => 'Skal udfyldes',
"inline" => TRUE
));
echo form_text('url', utf8_encode("LINK"), "", array(
"type" => "url",
"placeholder" => "http://",
"required" => TRUE,
"inline" => TRUE
));
echo "</div>\n";
echo "<div class='col-xs-12 col-sm-4'>\n";
openside("ELEMENTER");
echo form_checkbox("kategori", utf8_encode("KATEGORI"));
echo form_checkbox("menu", utf8_encode("MENU"));
echo form_checkbox("kontakt", utf8_encode("KONTAKTFORMULAR"),0);
closeside();
echo "</div>\n</div>\n";
echo form_button('opret_aktivitet',"GEM","GEM", array('class' => 'btn-primary m-t-10'));
echo closeform();
<?php
/**
* PHPFusion Infusion Development Tutorial
* Should you have any questions regarding this tutorial, please forward your concerns in the forum.
* Please state the line numbers of this gist code when discussing about this tutorial.
* Provided by MT, PHPFusion.co.uk
*
* Please follow the steps 1 to 4 when you practise coding.
* Notes are written as to why it is as such.
* Some original codes were altered to show common alternatives.
*/
// STEP 1, init blank values for all your fields
//(1) , point where data value is blank to be passed to form
$data = array(
"func" => "",
"navn" => "",
"url" => "",
"kategori" => "",
"menu" => "",
"kontakt" => "",
);
// STEP 2, do what happens if edit or delete... ?
/*
* Edit URL: http://www.site.com/infusions/script_infusion/script.php?action=edit&item_id=1
* Delete URL : http://www.site.com/infusions/script_infusion/script.php?action=del&item_id=1
*/
$edit = false;
if (isset($_GET['action'])) {
switch($_GET['action']) {
case "edit":
if (isset($_GET['item_id']) && isnum($_GET['item_id'])) {
// (2) point where blank $data is now filled with values from SQL Table.
$data = dbarray(dbquery("SELECT * FROM ..."));
$edit = true;
} else {
addNotice("danger", "Invalid Item ID");
redirect(FUSION_REQUEST);
}
break;
case "del":
if (isset($_GET['item_id']) && isnum($_GET['item_id'])) {
if (dbcount("(some_id)", SOME_DB, "some_id=''")) { // valid id and delete
dbquery("DELETE FROM .....");
addNotice("success", "Item deleted");
} else {
addNotice("danger", "Invalid Item ID");
redirect(FUSION_REQUEST);
}
} else {
addNotice("danger", "Invalid Item ID");
redirect(FUSION_REQUEST);
}
break;
}
}
// Step 4, Finally do what happens button is executed a step before openform() to read previous form settings session variables.
if (isset($_POST['opret_aktivitet'])) {
// This is the question how to validate in Php-Fusion 9
// Answer is like this, run form_sanitizer for everything..
$data = array(
"func" => form_sanitizer($_POST['func'], "", "func"), // post value, default value, input_name
"navn" => form_sanitizer($_POST['navn'], "", "navn"),
"url" => form_sanitizer($_POST['url'], "", "url"),
"kategori" => form_sanitizer($_POST['kategori'], "", "kategori"),
"menu" => form_sanitizer($_POST['menu'], "", "menu"),
"kontakt" => isset($_POST['kontakt']) ? 1 : 0, // if validation not needed, just do like this fastest result
);
// Use this to stop Insertion/Update to push $data downwards without refresh to see errors on input
if (\defender::safe()) {
if ($edit == true) {
dbquery_insert(DB_SOMETHING, $data, "update");
} else {
dbquery_insert(DB_SOMETHING, $data, "save");
}
redirect(FUSION_REQUEST); // Please refresh the page to reload page for new token for the form & security reason
}
}
// STEP 3, draw form and assign $data value from either (1) or (2)
openside("");
// Minor adjustments - since you need §ion, also you need to remember if there is &action, &item_id & $aid too
// The clean_request() is VERY powerful tool for infusion developers.
// If not just use FUSION_REQUEST as next recommended
echo openform("opret_aktivitet","POST", clean_request("section=ny_aktivitet", array("action", "item_id", "aid"), TRUE), array("class" => "m-t-20"));
echo "<div class='row'>\n";
echo "<div class='col-xs-12 col-sm-8'>\n";
echo form_hidden("func", $data['func']);
echo form_text("navn",utf8_encode("AKTIVITET"), $data['navn'],array(
'placeholder' => utf8_encode('Angiv navn på aktivitet'),
'required' => TRUE,
'width' => '250px',
'max_length' => 200,
'error_text' => 'Skal udfyldes',
"inline" => TRUE
));
echo form_text('url', utf8_encode("LINK"), $data['url'], array(
"type" => "url",
"placeholder" => "http://",
"required" => TRUE,
"inline" => TRUE
));
echo "</div>\n";
echo "<div class='col-xs-12 col-sm-4'>\n";
openside("ELEMENTER");
echo form_checkbox("kategori", utf8_encode("KATEGORI"), $data['kategori'], array("value" => "y")); // If your value is not 1/0
echo form_checkbox("menu", utf8_encode("MENU"), $data['menu'], array("reverse_label" => true)); // if you want to invert label
echo form_checkbox("kontakt", utf8_encode("KONTAKTFORMULAR"), $data['kontakt']);
closeside();
echo "</div>\n</div>\n";
echo form_button('opret_aktivitet',"GEM","GEM", array('class' => 'btn-primary m-t-10'));
echo closeform();
// This uploads your photo
if (!empty($_FILES['piktogram']) && is_uploaded_file($_FILES['piktogram']['tmp_name'])) {
$upload = form_sanitizer($_FILES['piktogram'], "", "piktogram");
if (empty($upload['error'])) {
$data['photo_filename'] = $upload['image_name'];
$data['photo_thumb1'] = $upload['thumb1_name'];
$data['photo_thumb2'] = $upload['thumb2_name'];
}
}
print_p($data);
dbquery_insert(DB_PIKTOGRAM, $data, "save");
// or
dbquery_insert(DB_PIKTOGRAM, $data, "update");
}
$upload_settings = array(
"upload_path" => BASEDIR.'billeder/',
'required' => 1,
'max_width' => $gll_settings['photo_max_w'],
'max_height' => $gll_settings['photo_max_h'],
'max_byte' => $gll_settings['photo_max_b'],
'multiple' => FALSE,
'delete_original' => FALSE,
'inline' => TRUE,
'error_text' => 'FEJL I BILLEDE',
'ext_tip' => sprintf($locale['photo_0017'], parsebytesize($gll_settings['photo_max_b']), str_replace(',', ' ', ".jpg,.gif,.png"), $gll_settings['photo_max_w'], $gll_settings['photo_max_h'])
);
echo form_fileinput("piktogram", "Piktogram", "", $upload_settings);
Category Forum
Modifications and Requests - 9Labels
None yet
Statistics
3 participants
Notifications
You are not receiving notifications from this thread.
Related Questions