Unable to access an error message corresponding to your field name -while uploading file in fuel cms in MY_Form_validation - fuelcms

I have written an validation rule on MY_Form_validation class under application -> library folder
as follow ..
public function doc_uploaded($field,$types)
{
$types=explode(',',$types);
$upload = $this->CI->lang->line('upload');
if(isset($_FILES[$field]) && !empty($_FILES[$field]['name']))
{
if(!function_exists('file_upload')){ $this->CI->load->helper('MY_file_helper'); }
$status = file_upload(($field),$_FILES[$field], captcha_path(),$types);
if($status >0 or strlen($status) > 2 )
{
return TRUE;
}
elseif(is_array($status))
{
$this->CI->_error_array[$field] = $status[0];
$this->CI->_error_array[$field] = $status[0];
$this->_error_array[$field]=sprintf( $upload,$this->_translate_fieldname($this->_field_data[$field]['label']));
// echo $field, print_r($this->_error_array);
// print_r($this->CI->_error_array);die();
return FALSE;
}
else
{
$this->_error_array[$field] = $status[0];
return FALSE;
}
}
else
{
return FALSE;
}
}
i am setting the validation rule from controller as follow
$this->form_validation->set_rules('resume', 'Resume', 'required|doc_uploaded[pdf,doc,docx,odt,txt,ppt,pptx]');
$_POST['resume'] ='resume';
now this one working fine except that error massage :
Unable to access an error message corresponding to your field name
Resume.(doc_uploaded)
must be an way to fix it please help . iam using 1.4

instead of
$this->_error_array[$field] = $status[0];
using
$this->CI->form_validation->set_message('doc_uploaded',$status[0]);
resolved the issue

Related

Codeigniter 4 with drag/drop multiple image uploader, validation

I am using a drag/drop image uploader script with my Codeigniter 4 project and it works well and I can use standard CI4 rules for validating file size, type, etc. but I need to check the max number of files being uploaded. I tried creating a custom rule but the data array does not contain the files. How should this be handled?
Below is test code in my controller when the form is submitted.
public function test_do()
{
helper(['form','url']);
$validation = \Config\Services::validation();
$rules = ['business_images' => ['label' => 'business image(s)',
'rules' => 'validate_images[business_images]']
];
if(!$this->validate($rules))
{
$error = $validation->getError('business_images');
echo 'Error - >'.$error;
}
else
{
echo 'good';
}
}
The image rule class is as follows.
class ImageRules
{
public function validate_images($str, string $fields, array $data, ?string &$error = null): bool
{
if(count($data['business_Images']) > 2)
{
$error = 'Too many files';
return false;
}
return true;
}
}

I wanted to update an existing record in asp.net mvc using Entity framework

I wanted to check if the productDiscount entity is already exist in the database, if it is exist then I wanted to update it. But instead of updating the entity the following code adds a new one. How to solve this problem..
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ProductDiscount(ProductDiscount productDiscount)
{
if (!ModelState.IsValid)
{
var viewModel = new ViewModelProductDiscount()
{
Products = _context.Products.ToList()
};
return View(viewModel);
}
var id = productDiscount.ProductId;
var disInDb = _context.ProductDiscounts.FirstOrDefault(p => p.ProductId == id);
if (disInDb==null)
{
_context.ProductDiscounts.Add(productDiscount);
_context.SaveChanges();
}
else
{
_context.ProductDiscounts.Add(disInDb);
_context.SaveChanges();
return Content(disInDb.Id.ToString());
}
return RedirectToAction("Products");
}
from the else block remove _context.ProductDiscounts.Add(disInDb); Just map the productDiscount values into disInDb and then _context.SaveChanges();
Like
else
{
disInDb.Name = productDiscount.Name;
disInDb.Discription = productDiscount.Discription;
_context.SaveChanges();
}
I don't really know how your ProductDiscount object looks like so I will assume your object props but it should give you an idea of how to update the record. Inside your else this line _context.ProductDiscounts.Add(disInDb); is what is causing the issue. Instead you want to do the following inside the else block
else
{
disInDb.DiscountCode = "somecode"; //change this to the correct prop name which needs updating
disInDb.DiscountProductName = "somename"; //change this to the correct prop name which needs updating
_context.SaveChanges();
}

Pagination link not work properly?

Pagination not work properly?
I saved this code in "Forum-Com.php" file and when i open this file, pagination works properly and correctly but when I include this file in another page, its open first page correctly but when I click second or another page link it open same comments which are on first page. Please help me. ( I am using Scriptsmill comments script v1.06 and function make_pages_string from admin.php )
$COM_CONF['full_path'] = dirname(__FILE__);
function make_pages_string ($all_count, $records_per_page, $cur_page, $base_url) {
if ($all_count > $records_per_page) {
if ($cur_page > 0) { $cur_page=$cur_page-1; }
$first_record = ($cur_page) * $records_per_page;
$limit_string = "LIMIT $first_record, $records_per_page";
$pages=$all_count/$records_per_page;
if ($pages > (int) $pages) { $pages=(int)$pages+1; }
}
if ($pages>1) {
$pages_string.="Page: ";
if ($cur_page>10 && $pages>20) { $first_page=$cur_page-9; }
else { $first_page=1; }
if ($pages>20 && ($cur_page+10)<$pages) { $last_page=$first_page+19; }
else { $last_page=$pages; }
if ($cur_page+1>1) {
$prev=$cur_page;
$pages_string.="<a href='$base_url&page=$prev'>&lt</a> ";
}
for ($i=$first_page; $i<=$last_page; $i++){
if ($i != $cur_page+1) {
$pages_string.="<a href='$base_url&page=$i'>$i</a> ";
}
else {
$pages_string.="<b>$i</b> ";
}
}
if ($cur_page+1<$pages) {
$next=$cur_page+2;
$pages_string.="<a href='$base_url&page=$next'>&gt</a> ";
}
}
return array ($pages_string, $limit_string);
}
function smcom_view()
{
global $comments_db_link, $COM_CONF, $COM_LANG;
$result = mysql_query("select COUNT(id) from {$COM_CONF['dbmaintable']}", $comments_db_link);
list ($all_count) = mysql_fetch_row($result);
list ($pages_string, $limit_string) = make_pages_string ($all_count, 10, $_REQUEST['page'], "{$COM_CONF['base_url']}?action=view");
$result = mysql_query("select time, text, author, email, dont_show_email from {$COM_CONF['dbmaintable']} order by time {$COM_CONF['sort_order']} $limit_string", $comments_db_link);
$comments_count=0;
$id=$time=$text=$author=$email=$dont_show_email=$ip=array();
while (list($id[$comments_count], $time[$comments_count], $text[$comments_count], $author[$comments_count], $email[$comments_count], $dont_show_email[$comments_count], $ip[$comments_count])=mysql_fetch_array($result)) {
$comments_count++;
}
require("{$COM_CONF['full_path']}/templates/Forum-default.php");
}
The code given above has no problem at all. The problem is with the server configuration which turned off $_REQUEST global variable from direct access.

Activated Solution on Sharepoint 2010 is not visible

I have activated a WSP file which includes a website template. This works and I can see the solution int he solution gallery. When I try to create a website, based on that template, its not showing up. But it says "Status: Activated".
Then I tried to deactivate it and activate it again manually. Out of a sudden, there is a new template showing up, which takes the name of my template appended by a "2".
So whats happening here exactly? The code to activate my solution is:
System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);
SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
try
{
SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
}
catch { ... }
Ok, I found the answer myself and want to share it here. The solution is, not to provide the solution in the catalog, but also to enable the features! It works like this:
System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);
SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
try
{
SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
Guid solutionId = newUserSolution.SolutionId;
SPFeatureDefinitionCollection siteFeatures = web.Site.FeatureDefinitions;
var features = from SPFeatureDefinition f
in siteFeatures
where f.SolutionId.Equals(solutionId) && f.Scope == SPFeatureScope.Site
select f;
foreach (SPFeatureDefinition feature in features)
{
try
{
web.Site.Features.Add(feature.Id, false, SPFeatureDefinitionScope.Site);
}
catch { }
}
SPWebTemplateCollection webTemplates = web.Site.RootWeb.GetAvailableWebTemplates(1033);
SPWebTemplate webTemplate = (from SPWebTemplate t
in webTemplates
where t.Title == "Projekt"
select t).FirstOrDefault();
if (webTemplate != null)
{
try
{
web.Site.RootWeb.ApplyWebTemplate(webTemplate.Name);
}
catch { }
}
}
catch { ... }

Non-unique ldap attribute name with Unboundit LDAP SDK

I am attempting to retrieve objects having several attributes with the name from netscape LDAP directory with LDAP SDK from Unboundit. The problem is that only one of the attributes are returned - I am guessing LDAP SDK relays heavily on unique attribute names, is there a way to configure it to also return non-distinct attributes as well?
#Test
public void testRetrievingUsingListener() throws LDAPException {
long currentTimeMillis = System.currentTimeMillis();
LDAPConnection connection = new LDAPConnection("xxx.xxx.xxx", 389,
"uid=xxx-websrv,ou=xxxx,dc=xxx,dc=no",
"xxxx");
SearchRequest searchRequest = new SearchRequest(
"ou=xxx,ou=xx,dc=xx,dc=xx",
SearchScope.SUB, "(uid=xxx)", SearchRequest.ALL_USER_ATTRIBUTES );
LDAPEntrySource entrySource = new LDAPEntrySource(connection,
searchRequest, true);
try {
while (true) {
try {
System.out.println("*******************************************");
Entry entry = entrySource.nextEntry();
if (entry == null) {
// There are no more entries to be read.
break;
} else {
Collection<Attribute> attributes = entry.getAttributes();
for (Attribute attr : attributes)
{
System.out.println (attr.getName() + " " + attr.getValue());
}
}
} catch (SearchResultReferenceEntrySourceException e) {
// The directory server returned a search result reference.
SearchResultReference searchReference = e
.getSearchReference();
} catch (EntrySourceException e) {
// Some kind of problem was encountered (e.g., the
// connection is no
// longer valid). See if we can continue reading entries.
if (!e.mayContinueReading()) {
break;
}
}
}
} finally {
entrySource.close();
}
System.out.println("Finished in " + (System.currentTimeMillis() - currentTimeMillis));
}
Non-unique LDAP attributes are considered multivalued and are reperesented as String array.
Use Attribute.getValues() instead of attribute.getValue.

Resources