Yii: ClientSide Validation on FileField and TextField - yii

I have a yii form with a file field and a normal text field for supplying an external image url. I managed to get a normal server validation working which checks that only one of the two form fields is filled out (because you can either provide a local file for uploading OR an external picture URL). Important to notice is, that the attribute value of the "file field" seems only to be available after the $_POST var is set, meaning that a normal custom validation rule in the Model Class won't work since the $_POST value of the file field is only available after submission (in the $_FILES var).
But if you look at my provided picture below, I want also a ClientSide Validaton, so that the user gets immediate feedback that it's not allowed to fill out both fields. But how do I accomplish that? I'm sitting on this problem for about 2 days, half of the time on searching for solutions...I am new to Yii.
http://www.prism-informatics.com/images/demo.png
Best wishes,
S

I am not completely sure what your problems is as you didnt provide any code but i assume you forgot :
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}

Related

How to store the contains of a dijit editor containing image and text in a database?

I am trying to make an input field which accepts text and image with copy/paste feature. I am looking for a way to save the contains of this field and then retrieve and display the same in non-editable field.
Can this be done with dijit.editor?
I appreciate any tip on this. Thank you.
You will need more than just digit.Editor.
You will need at least something like:
digit/Editor for the writable UI
div for the readonly UI
dojo/request for sending Editor value to backend and for getting saved value from the DB
A server able to handle non static pages (like Apache + php)
A database (like mysql)
A backend API to save and read from the database

DNN get params in view are not available in edit

I am creating a dnn module. The content depends on the param in the url.
I want to be able to edit this content in the 'edit content' mode. However when i go to edit content the param in the url is no longer accessible because it is the parent document. How do i go about passing this value from the view.ascx to the edit.ascx?
Try storing the param in cookies or localstorage. Then you should be able to access it. Of course the user will be able to modify it but you can do a check that the user has not modified it by storing a server side encryption or somthing like that.
A workaround is to have a field where the user enters this parameter. But i know this isn't a very good solution. I am guessing that you will have to override the dotnetnuke core to do this (yes i know it sucks).
I hope I am understanding the question properly.
To pass parameters from your View to Edit controls, you should first make sure they are registered properly in the module definition. You default View should have an empty controlkey and your Edit should be registered with a control key, for example "addedit".
When creating a link between your view control and edit control, use the EditUrl() method of PortalModuleBase. When passing a parameter, for example an id of the item you want to load into your edit control, you can pass them as arguments in the EditUr method.
Example (in my view.ascx.cs):
lnkEdit.NavigateUrl = EditUrl("id", "16", "addedit");
This will assign a module view link to the edit.ascx (assuming the controlkey in the definition is addedit) passing in a url parameter "id" with value 16.
See my DNN Module Views tutorial for a complete lesson on how to do DNN module views and navigation.
http://www.dnnhero.com/Premium/Tutorial/tabid/259/ArticleID/204/Introduction-and-Module-Definition-basics-in-DNN-Part-1-6.aspx

Disable validation in Yii

I am trying to implement a "Save as Draft" functioning in my project using Yii. I have a form with 2 buttons :- Submit and Save . On clicking the Submit button , after validating all the fields including required fields the form data is saved into the database. It works perfect. On clicking Save button I need to save the form data without default validations into the database. How can I implement this disabling of validation in a controller action ??
All advices are acceptable..
Thanks
Turning off validation rules all together is easy:
$model->save(false);
This will not do any validation and will just try and save your model (may still fail on the database side).
But if you want to run some validation ,you might want to look into Scenarios here. They allow you to specify a different set of rules depending on which scenario you initialize the model with. That way you can only turn on/off whole sets of validation rules.
$model = new Thingy();
$model->save(); // All default validation rules
$model = new Thingy('draft');
$model->save(); //Applies all default & "draft" validation rules
Your question says in Controller but as far as I know, in controller we have filters which do for example check the permissions. That can be overridden as explained in this section of the guide. If you meant the validation that is done in model, then you can use scenarios (bypass validation by binding rules to scenario and no validation in other scenarios).
Check this thread that discuss a like problem
If I have misunderstood your question please comment here so that I update the answer accordingly!

Persist CMultiFileUpload selection through input validation

I'm using a CMultiFileUpload control in one of my forms like this:
$this->widget('CMultiFileUpload', array(
'name' => 'neueAnhaenge',
));
When input validation for some other form element fails and the input form is rendered again, a previous selection in this control is gone (as expected).
How do I repopulate this control, what do I have to do in my controller, is there a way to prepopulate this?
Thanks in advance.
For file fields it is rather impossible to reset the values assigned to it after it has been sent to the server.
One way to solve this would be to get the uploaded files, store them temporarily on the server and modify the form so it sends a reference to the file on the server.
A much better way would be to use Ajax or Client side validation of form fields to ensure no validation error occures when form has been sent. You can enable these options for CActiveForm: $enableClientValidation and $enableAjaxValidation.

PrestaShop - Reload CMS page with additional parameters

Situation: I needed to add form with POST method to CMS page. I created custom hook and a module displaying the form successfully. Then I need to react to user input errors eg. when user doesn't enter email address I need to detect it, display the whole page again together with the form and with "errors" in user input clearly stated.
Problem: The problem is to display the WHOLE page again with connected information (eg. about errors etc.). In the module PHP file when I add this kind of code,
return $this->display(__FILE__, 'modulename.tpl');
it (naturally) displays ONLY the form, not the whole CMS page with the form.
In case of this code,
Tools::redirectLink('cms.php?id_cms=7');
I can't get to transfer any information by GET neither POST method.
$_POST['test'] = 1;
Tools::redirectLink('cms.php?id_cms=7&test');
I tried to assign to smarty variables too
$smarty->assign('test', '1');
(I need to use it in .tpl file where the form itself is created) but no way to get it work.
{if isset($test)}...,
{if isset($smarty.post.test)}...,
{if isset($_POST['test'])}... {* neither of these conditionals end up as true *}
Even assigning a GET parameter to url has no impact, because there is link rewriting to some kind of friendly url I guess, no matter I included other argument or not. ([SHOPNAME]/cms.php?id_cms=7&test -> [SHOPNAME]/content/7-cmspage-name)
My question is: is there a way to "redirect" or "reload" current page (or possibly any page generally) in prestashop together with my own data included?
I kind of explained the whole case so I'm open to hear a better overall solution than my (maybe I'm thinking about the case in a wrong way at all). This would be other possible answer.
The simplest method would be to use javascript to validate the form - you can use jQuery to highlight the fields that are in error; providing visual feedback on how the submission failed. In effect you don't allow the user to submit the form (and thus leave the page) until you're happy that the action will succeed. I assume that you will then redirect to another page once a successful submission has been received.
There's lots of articles and how-tos available for using javascript, and indeed jQuery for form validation. If you want to keep the site lean and mean, then you can provide an override for the CMS controller and only enqueue the script for the specific page(s) you want to use form validation on.
If the validation is complex, then you might be best using AJAX and just reloading the form section of your page via a call to your module. Hooks aren't great for this kind of thing, so you might want to consider using an alternative mnethod to inject your code onto the cms page. I've written a few articles on this alternative approach which can be found on my prestashop blog