Search Results

Search found 7702 results on 309 pages for 'django validation'.

Page 52/309 | < Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >

  • jquery form wizard validation

    - by SoulieBaby
    Hi all, I'm trying to implement a validation script (bassistance) with a jquery form wizard (http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx) but I'm having some problems. On the page for the jquery wizard, a guy named "Tommy" came up with a piece of code to implement bassistance with the code. But for some reason I can't get it to work. It comes up saying if the field needs to be filled in etc and the next button doesn't work - which is fine, BUT, if I fill in all the fields, the next button still doesn't work.. function createNextButton(i) { var stepName = "step" + i; $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next ></a>"); /* VALIDATION */ if (options.validationEnabled) { var stepIsValid = true; $("#" + stepName + " :input").each(function(index) { stepIsValid = !element.validate().element($(this)) && stepIsValid; }); if (!stepIsValid) { return false; } } /* END VALIDATION */ $("#" + stepName + "Next").bind("click", function(e) { $("#" + stepName).hide(); $("#step" + (i + 1)).show(); if (i + 2 == count) $(submmitButtonName).show(); selectStep(i + 1); }); } Could someone help me figure this one out? :)

    Read the article

  • MVC2 Client Validation isn't working when getting form from ajax call

    - by devlife
    I'm trying to use MVC2 client-side validation in a partial view that is rendered via $.get. However, the client validation isn't working. I'm not quite sure what the deal is. [Required(ErrorMessage = "Email is required")] public string Email { get; set; } <% using ( Ajax.BeginForm( new AjaxOptions { Confirm = "You sure?" } ) ) { %> <%: Html.TextBoxFor( m => m.Email, new { @class = "TextBox150" } )%> <%= Html.ValidationMessageFor( m => m.Email )%> <input type="submit" value="Add/Save" style="float: right;" /> <% } %> I'm not doing anything special to render the the partial view. Just putting the html into a div and showing it in a modal popup. On a side note, does anyone know if it's possible to submit the form with client validation without a submit button?

    Read the article

  • How to Persist URL parameters when CakePHP form validation fails

    - by am2605
    Hi, I'm new to cakephp and trying to write a simple app with it, however I'm stuck with some form validation issues. I have a model named "Person" which hasMany "PersonSkill" objects. To add a "PersonSkill" to a person, I have set it up to call a url like this: http://localhost/myapp/person_skills/add/person_id:3 I have been passing through the person_id because I want to display the name of the person we are adding the skills for. My issue is if the validation fails, the person_id parameter is not persisted to the next request, so the person's name is not displayed. The add method on the controller looks like this: function add() { if (!empty($this->data)) { if ($this->PersonSkill->save($this->data)) { $this->Session->setFlash('Your person has been saved.'); $this->redirect(array('action' => 'view', 'id' => $this->PersonSkill->id)); } } else { $this->Person->id = $this->params['named']['person_id']; $this->set('person', $this->Person->read()); } } In my person_skill add.ctp I set a hidden field which holds the person_id, eg: echo $form->input('person_id', array('type'=>'hidden','value'=>$person['Person']['id'])); Is there a way to persist the person_id url parameter when form validation fails, or is there a better way to do this that I'm missing completely? Any advice would be greatly appreciated.

    Read the article

  • jQuery Validation plugin results in empty AJAX POST

    - by user305412
    Hi, I have tried to solve this issue for at couple of days with no luck. I have a form, where I use the validation plugin, and when I try to submit it, it submits empty vars. Now, if I remove the validation, everything works fine. Here is my implementation: $(document).ready(function(){ $("#myForm").validate({ rules: { field1: { required: true, minlength: 5 }, field2: { required: true, minlength: 10 } }, messages: { field1: "this is required", field2: "this is required", }, errorLabelContainer: $("#validate_msg"), invalidHandler: function(e, validator) { var errors = validator.numberOfInvalids(); if (errors) { $("#validate_div").show(); } }, onkeyup: false, success: false, submitHandler: function(form) { doAjaxPost(form); } }); }); function doAjaxPost(form) { // do some stuff $(form).ajaxSubmit(); return false; } As I wrote this does not work when I have my validation, BUT if I remove that, and just add an onsubmit="doAjaxPost(this.form); return false"; to my HTML form, it works - any clue??? Now here is the funny thing, everything works as it should in Safari, but not in firefox 3.6.2 (Mac OS X)!

    Read the article

  • wpf & validation application block > message localization > messageTemplateResource Name&Type

    - by Shaboboo
    I'm trying to write validation rules for my data objects in a WPF application. I'm writing them in the configuration file, and so far they are working fine. I'm stumped on how to localize the messages using messageTemplateResourceName and messageTemplateResourceType. What I know is that the strings can be writen in a resource file, given a name and referenced by that name. I get the idea, but i haven't been able to make this work. <ruleset name="Rule Set"> <properties> <property name="StringValue"> <validator lowerBound="0" lowerBoundType="Ignore" upperBound="25" upperBoundType="Inclusive" negated="false" messageTemplate="" messageTemplateResourceName="msg1" messageTemplateResourceType="Resources" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation" name="String Length Validator" /> </property> </properties> </ruleset> Where is the resource file and what value do I pass to messageTemplateResourceType? I have tried writing the messages in the shell project's resource file but no sucess trying to retrieve the value. I only get the default built-in message. I've tried messageTemplateResourceType="typeof(Resources)" messageTemplateResourceType="Resources" messageTemplateResourceType="Resources.resx" messageTemplateResourceType="typeof(Shell)" messageTemplateResourceType="Shell" messageTemplateResourceType="Shell, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" I've also tried adding a new resource file in the shell project, and adding a resource file to the data object's library. I'm all out of ideas Does anyone have any suggestions? I'm not even married to the idea of resource files, so if there are other ways to localize these messages I'd love to know! thanks

    Read the article

  • ASP.NET MVC Conditional validation

    - by Peter Stegnar
    How to use data annotations to do a conditional validation on model? For example, lets say we have the following model (Person and Senior): public class Person { [Required(ErrorMessage = "*")] public string Name { get; set; } public bool IsSenior { get; set; } public Senior Senior { get; set; } } public class Senior { [Required(ErrorMessage = "*")]//this should be conditional validation, based on the "IsSenior" value public string Description { get; set; } } And the following view: <%= Html.EditorFor(m => m.Name)%> <%= Html.ValidationMessageFor(m => m.Name)%> <%= Html.CheckBoxFor(m => m.IsSenior)%> <%= Html.ValidationMessageFor(m => m.IsSenior)%> <%= Html.CheckBoxFor(m => m.Senior.Description)%> <%= Html.ValidationMessageFor(m => m.Senior.Description)%> I would like to be the "Senior.Description" property conditional required field based on the selection of the "IsSenior" propery (true - required). How to implement conditional validation in ASP.NET MVC 2 with data annotations? UPDATE Found nice solution. Look below.

    Read the article

  • Constraint Validation

    - by tanuja
    I am using javax.validation.Validator and relevant classes for annotation based validation. Configuration<?> configuration = Validation.byDefaultProvider().configure(); ValidatorFactory factory = configuration.buildValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<ValidatableObject>> constraintViolations = validator.validate(o); for (ConstraintViolation<ValidatableObject> value : constraintViolations) { List< Class< ? extends ConstraintValidator< ? extends Annotation,?>>> list = value.getConstraintDescriptor().getConstraintValidatorClasses(); } I get a compilation error stating: Type mismatch: cannot convert from List< Class< ? extends ConstraintValidator< capture#4-of ?,? to List< Class< ? extends ConstraintValidator< ? extends Annotation,? What am I missing?

    Read the article

  • Disable validation in an object in Ruby on Rails

    - by J. Pablo Fernández
    I have an object which whether validation happens or not should depend on a boolean, or in another way, validation is optional. I haven't found a clean way to do it. What I'm currently doing is this (disclaimer: you cannot unsee, leave this page if you are too sensitive): def valid? if perform_validation super else super # Call valid? so that callbacks get called and things like encrypting passwords and generating salt in before_validation actually happen errors.clear # but then clear the errors true # and claim ourselves to be valid. This is super hacky! end end Any better ways? Before you point to the :if argument of many validations, this is for a user model which is using authlogic so it has a lot of validation rules. You can stop reading here if you belive me. If you don't, authlogic already sets some :ifs like: :if => :email_changed? which I have to turn into :if => Proc.new {|user| user.email_changed? and user.perform_validation} and in some other cases, since I'm also using authlogic-oid (OpenID) I just don't have control over the :if, authlogic-oid sets it in a way I cannot change it (in time) without further monkey patching. So I have to override seemingly unrelated functions, catch exceptions if a method doesn't exist, etc. The previous hacky solution if the best of my two attempts.

    Read the article

  • PHP form validation function

    - by Barbs
    I am currently writing some PHP form validation (I have already validated clientside) and have some repetitive code that I think would work well in a nice little PHP function. However I have having trouble getting it to work. I'm sure it's just a matter of syntax but I just can't nail it down. Any help appreciated. //Validate phone number field to ensure 8 digits, no spaces. if(0 === preg_match("/^[0-9]{8}$/",$_POST['Phone']) { $errors['Phone'] = "Incorrect format for 'Phone'"; } if(!$errors) { //Do some stuff here.... } I found that I was writing the validation code a lot and I could save some time and some lines of code by creating a function. //Validate Function function validate($regex,$index,$message) { if(0 === preg_match($regex,$_POST[$index],$message) { $errors[$index] = $message; } And call it like so.... validate("/^[0-9]{8}$/","Phone","Incorrect format for Phone"); Can anyone see why this wouldn't work? Note I have disabled the client side validation while I work on this to try to trigger the error, so the value I am sending for 'Phone' is invalid.

    Read the article

  • Detect whether or not a specific attribute was valid on the model

    - by Sir Code-A-Lot
    Having created my own validation attribute deriving from System.ComponentModel.DataAnnotations.ValidationAttribute, I wish to be able to detect from my controller, whether or not that specific attribute was valid on the model. My setup: public class MyModel { [Required] [CustomValidation] [SomeOtherValidation] public string SomeProperty { get; set; } } public class CustomValidationAttribute : ValidationAttribute { public override bool IsValid(object value) { // Custom validation logic here } } Now, how do I detect from the controller whether validation of CustomValidationAttribute succeeded or not? I have been looking at the Exception property of ModelError in the ModelState, but I have no way of adding a custom exception to it from my CustomValidationAttribute. Right now I have resorted to checking for a specific error message in the ModelState: public ActionResult PostModel(MyModel model) { if(ModelState.Where(i => i.Value.Errors.Where((e => e.ErrorMessage == CustomValidationAttribute.SharedMessage)).Any()).Any()) DoSomeCustomStuff(); // The rest of the action here } And changed my CustomValidationAttribute to: public class CustomValidationAttribute : ValidationAttribute { public static string SharedMessage = "CustomValidationAttribute error"; public override bool IsValid(object value) { ErrorMessage = SharedMessage; // Custom validation logic here } } I don't like relying on string matching, and this way the ErrorMessage property is kind of misused. What are my options?

    Read the article

  • ASP.NET MVC2 Model Validation Fails with Non-US Date Format

    - by 81bronco
    I have a small MVC2 app that displays in two cultures: en-US and es-MX. One portion contains a user input for a date that is pre-populated with the current date in the Model. When using en-US, the date field is displayed as MM/dd/yyyy and can be changed using the same format without causing any validation errors. When using es-MX, the date field is displayed as dd/MM/yyyy, but when the date is edited in this format, the server-side validation fails with the message: The value '17/05/1991' is not valid for The Date. One of the first things that jumps out at me about that message is that it is not localized. Both the message itself (which I do not think I can control) and the Display Name of the field (which I can control and is localized in my code). Should be displaying in a localized format. I have tried stepping through the code to see exactly where the validation is failing, but it seems to be happening inside some of the compiled MVC or DataAnnotations code that I cannot see. Application details: IIS6, ASP.NET 3.5 (C#), MVC 2 RTM Sample Model Code: public class TestVieModel{ [LocalizedDisplayNameDisplayName("TheDateDisplayName", NameResourceType=typeof(Resources.Model.TestViewModel))] [Required(ErrorMessageResourceName="TheDateValidationMessageRequired", ErrorMessageResourceType=typeof(Resources.Model.TestViewModel))] [DataType(DataType.Date)] public DateTime TheDate { get; set; } } Sample Controller Action Code: [HttpPost] [ValidateAntiForgeryToken] public ActionResult Save(TestViewModel model) { if(ModelState.IsValid) { // <--- Always is false when using es-MX and a date foramtted as dd/MM/yyyy. // Do other stuff return this.View("Complete", model); } // Validation failed, redisplay the form. return this.View("Enter", model); } Sample View Code: <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HispanicSweeps.Web.Model.LosMets.EnterViewModel>" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Test</title> </head> <body> <% using (Html.BeginForm()) {%> <%= Html.ValidationSummary(true) %> <fieldset> <legend>Fields</legend> <div class="editor-label"> <%= Html.LabelFor(model => model.DateOfBirth) %> </div> <div class="editor-field"> <%= Html.EditorFor(model => model.DateOfBirth) %> <%= Html.ValidationMessageFor(model => model.DateOfBirth) %> </div> <p><input type="submit" value="Save" /></p> </fieldset> <% } %> </body> </html>

    Read the article

  • Business rule validation of hierarchical list of objects ASP.NET MVC

    - by SergeanT
    I have a list of objects that are organized in a tree using a Depth property: public class Quota { [Range(0, int.MaxValue, ErrorMessage = "Please enter an amount above zero.")] public int Amount { get; set; } public int Depth { get; set; } [Required] [RegularExpression("^[a-zA-Z]+$")] public string Origin { get; set; } // ... another properties with validation attributes } For data example (amount - origin) 100 originA 200 originB 50 originC 150 originD the model data looks like: IList<Quota> model = new List<Quota>(); model.Add(new Quota{ Amount = 100, Depth = 0, Origin = "originA"); model.Add(new Quota{ Amount = 200, Depth = 0, Origin = "originB"); model.Add(new Quota{ Amount = 50, Depth = 1, Origin = "originC"); model.Add(new Quota{ Amount = 150, Depth = 1, Orinig = "originD"); Editing of the list Then I use Editing a variable length list, ASP.NET MVC 2-style to raise editing of the list. Controller actions QuotaController.cs: public class QuotaController : Controller { // // GET: /Quota/EditList public ActionResult EditList() { IList<Quota> model = // ... assigments as in example above; return View(viewModel); } // // POST: /Quota/EditList [HttpPost] public ActionResult EditList(IList<Quota> quotas) { if (ModelState.IsValid) { // ... save logic return RedirectToAction("Details"); } return View(quotas); // Redisplay the form with errors } // ... other controller actions } View EditList.aspx: <%@ Page Title="" Language="C#" ... Inherits="System.Web.Mvc.ViewPage<IList<Quota>>" %> ... <h2>Edit Quotas</h2> <%=Html.ValidationSummary("Fix errors:") %> <% using (Html.BeginForm()) { foreach (var quota in Model) { Html.RenderPartial("QuotaEditorRow", quota); } %> <% } %> ... Partial View QuotaEditorRow.ascx: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Quota>" %> <div class="quotas" style="margin-left: <%=Model.Depth*45 %>px"> <% using (Html.BeginCollectionItem("Quotas")) { %> <%=Html.HiddenFor(m=>m.Id) %> <%=Html.HiddenFor(m=>m.Depth) %> <%=Html.TextBoxFor(m=>m.Amount, new {@class = "number", size = 5})%> <%=Html.ValidationMessageFor(m=>m.Amount) %> Origin: <%=Html.TextBoxFor(m=>m.Origin)%> <%=Html.ValidationMessageFor(m=>m.Origin) %> ... <% } %> </div> Business rule validation How do I implement validation of business rule: Amount of quota and sum of amounts of nested quotas should equal (e.a. 200 = 50 + 150 in example)? I want to appropriate inputs Html.TextBoxFor(m=>m.Amount) be highlighted red if the rule is broken for it. In example if user enters not 200, but 201 - it should be red on submit. Using sever validation only. Thanks a lot for any advise.

    Read the article

  • What is the proper way to check the previous value of a field before saving an object? (Using Django

    - by anonymous coward
    I have a Django Model with updated_by and an approved_by fields, both are ForeignKey fields to the built-in (auth) User models. I am aware that with updated_by, it's easy enough to simply over-ride the .save() method on the Model, and shove the request.user in that field before saving. However, for approved_by, this field should only ever be filled in when a related field (date_approved) is first filled in. I'm somewhat certain that I can check this logically, and fill in the field if the previous value was empty. What is the proper way to check the previous value of a field before saving an object? I do not anticipate that date_approved will ever be changed or updated, nor should there be any reason to ever update the approved_by entry. UPDATE: Regarding forms/validation, I should have mentioned that none of the fields in question are seen by or editable by users of the site. If I have misunderstood, I'm sorry, but I'm not sure how forms and validation apply to my question.

    Read the article

  • Apache/Django subdomains problem

    - by thomasgg
    Now I have apache configuration which works only with localhost domain (http://localhost/). Alias /media/ "/sciezka/do/instalacji/django/contrib/admin/media/" Alias /site_media/ "/sciezka/do/plikow/site_media/" <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE settings PythonPath "['/thomas/django_projects/project'] + sys.path" PythonDebug On </Location> <Location "/site_media"> SetHandler none </Location> How can I make it working for some subdomains like pl.localhost or uk.localhost? This subdomains should display the same page what domain (localhost). Second question: It is possible change default localhost address (http://localhost/) to (http://localhost.com/) or (http://www.localhost.com/) or something else?

    Read the article

  • Django Dying on Shared Hosting Environment (Too Many MySQL Connections)

    - by Tom
    I've had a Django site up and running on HostGator (client requirement), following these instructions, for a few weeks now. I had seen two error emails about pages dying with (1040: Too many MySQL connections) but had never been able to recreate the problem. As of today, the site is completely unresponsive and all pages, even the static files, are dying with that error. Two questions: What can I do to fix this (other than caching more stuff)? Why would static files be dying like that? I can request them directly without a problem, so how are they getting run through Django? The shared hosting setup doesn't allow for a <Location> block, but there's a flag in the rewrite rule that says only requests for files that don't exist in the filesystem should be processed. All of my static files exist on the system, though they are symbolically linked files if it matters.

    Read the article

  • Running django custom management commands with supervisord

    - by mfsaint
    I'd like to use supervisord to run some commands for my Django project but I keep getting the following error: supervisor.log: 2012-05-18 17:52:15,784 INFO spawnerr: can't find command 'source' If I remove the "source" command, the log shows the same error: can't find command 'python'. supervisord.conf excerpt: [program:django] directory=/home/mf/projects/djangopj/ command=beanstalkd -l 127.0.0.1 -p 11300 command=source /home/mf/virtualenvs/env/bin/activate command=python manage.py command1 command=python manage.py command2 user=mf autostart=true autorestart=true I tried removing the directory and adding the absolute path to the commands but I kept getting the same error. I run supervisord with the following command: supervisord -c supervisord.conf -l supervisor.log

    Read the article

  • Apache, Django with mod_wsgi, and large request buffering

    - by Mukul
    In my setup of Apache 2.2 MPM worker and Django 1.3 with mod_wsgi 2.8, I need to support large POST request payloads. The problem is that when there are many such simultaneous requests, Apache uses up all the memory in the system and then crashes. It seems that Apache is buffering the requests completely in memory before executing the WSGI handler and passing it the request. Is there any way to control request buffering in Apache? The log shows the following error whenever the crash happens: [Wed Jun 29 18:35:27 2011] [error] cgid daemon process died, restarting Here's my virtual host's configuration: <VirtualHost *:8080> ServerName example.com ErrorLog /var/log/apache2/error.log WSGIScriptAlias / <path to django.wsgi> WSGIPassAuthorization on WSGIDaemonProcess example.com WSGIProcessGroup example.com XSendFileAllowAbove on XSendFile on </VirtualHost>

    Read the article

  • Nginx / uWsgi / Django site can handle more traffic with rewrite URL

    - by Ludo
    Hi there. I'm running a Django app, using uWsgi behind Nginx. I've been doing some performance tuning and load testing using ApacheBench and have discovered something unexpected which I wonder if someone could explain for me. In my Nginx config I have a rewrite directive which catches lots of different URL permutations and then forwards them to the canonical URL I wish to use, eg, it traps www.mysite.com/whatever, www.mysite.co.uk/whatever and forwards them all to http://mysite.com/whatever. If I load test against any of the URLs listed with a redirect (ie, NOT the canonical URL which it is eventually forwarded to), it can serve 15000 concurrent connections without breaking a sweat. If I load test against the canonical URL, which the above test I would have expected got forwarded to anyway, it can't handle nearly as much. It will drop about 4000 of the 15000 requests, and can only handle about 9000 reliably. This is the command line I'm using to test: ab -c15000 -n15000 http://www.mysite.com/somepath/ and ab -c15000 -n15000 http://mysite.com/somepath/ I've tried several different types - it makes no different which order I do them in. This doesn't make sense to me - I can understand why the requests involving a redirect may not handle quite so many concurrent connections, but it's happening the other way round. Can anyone explain? I'd really prefer it if the canonical URL was the one which could handle more traffic. I'll post my Nginx config below. Thanks loads for any help! server { server_name www.somesite.com somesite.net www.somesite.net somesite.co.uk www.somesite.co.uk; rewrite ^(.*) http://somesite.com$1 permanent; } server { root /home/django/domains/somesite.com/live/somesite/; server_name somesite.com somesite-live.myserver.somesite.com; access_log /home/django/domains/somesite.com/live/log/nginx.log; location / { uwsgi_pass unix:////tmp/somesite-live.sock; include uwsgi_params; } location /media { try_files $uri $uri/ /index.html; } location /site_media { try_files $uri $uri/ /index.html; } location = /favicon.ico { empty_gif; } }

    Read the article

  • Web Server for SVN+PHP+Django+Rails

    - by NetStudent
    Foreword: I am not asking for the differences between Nginx and Apache, nor do I want to start a "which one is better discussion. I would like to ask for help with choosing the most adequate solution for this particular situation. I need to setup one or more l SVN repositories accessible via HTTP, plus some PHP, Django and Ruby websites. However, and since I only have 512Mb of RAM at my disposal, I fear that Apache will be a too heavy choice... On the other hand, I have heard that Nginx does not fully support SVN (WebDAV) and Django without reverse proxying to Apache. Is this still true? Should I go for Apache/Nginx alone? Or should I set up both and have Nginx handling static content and proxying to Apacge for dynamic content?

    Read the article

  • Django freezes when adding objects through the admin

    - by Quartz
    I have a Django 1.1 website running via Apache/mod_wsgi with a PostgreSQL 8.3.1 database. Recently, when I added objects through the admin interface, the connection froze up and I lost several worker processes, so I had to restart Apache. Upon trying to replicate this, I found that it only happens through the admin: if I go into the Django shell and issue the same insert, it works fine. Also, performing an UPDATE operation works without issues, so just INSERTs. I've rebuilt indexes on PostgreSQL and run a full VACUUM. Error logs don't show anything, and I can't figure out for the life of me what's wrong. Anyone have any ideas?

    Read the article

  • NGinX config for Django and Wordpress in subdirectory

    - by Helmut
    I need to set up a Django site at the root of a domain, but then have a Wordpress installation in a subdirectly (e.g. /blog/). How would one configure NGinX to do this? "Pretty" URLs have to work for Wordpress as well. For Django I am using Gunicorn, which is already configured. From NGinX I would call "proxy_pass" to direct to that. PHP is run via FPM. Considering the restrictions above, how would I configure NGinX? Any help would be appreciated! Thanks.

    Read the article

  • PHP form class

    - by Oli
    I'm used to ASPNET and Django's methods of doing forms: nice object-orientated handlers, where you can specify regexes for validation and do everything in a very simple way. After months living happily without it, I've had to come back to PHP for a project and noticed that everything I used to do with PHP forms (manual output, manual validation, extreme pain) was utter rubbish. Is there a nice, simple and free class that does form generation and validation like it should be done? Clonefish has the right idea, but it's way off on the price tag.

    Read the article

  • Why is my django bulk database population so slow and frequently failing?

    - by bryn
    I decided I'd like to use django's model system rather than coding raw SQL to interface with my database, but I am having a problem that surely is avoidable. My models.py contains: class Student(models.Model): student_id = models.IntegerField(unique = True) form = models.CharField(max_length = 10) preferred = models.CharField(max_length = 70) surname = models.CharField(max_length = 70) and I'm populating it by looping through a list as follows: from models import Student for id, frm, pref, sname in large_list_of_data: s = Student(student_id = id, form = frm, preferred = pref, surname = sname) s.save() I don't really want to be saving this to the database each time but I don't know another way to get django to not forget about it (I'd rather add all the rows and then do a single commit). There are two problems with the code as it stands. It's slow -- about 20 students get updated each second. It doesn't even make it through large_list_of_data, instead throwing a DatabaseError saying "unable to open database file". (Possibly because I'm using sqlite3.) My question is: How can I stop these two things from happening? I'm guessing that the root of both problems is that I've got the s.save() but I don't see a way of easily batching the students up and then saving them in one commit to the database.

    Read the article

  • ASP.NET MVC 2 loading partial view using jQuery - no client side validation

    - by brainnovative
    I am using jQuery.load() to render a partial view. This part looks like this: $('#sizeAddHolder').load( '/MyController/MyAction', function () { ... }); The code for actions in my controller is the following: public ActionResult MyAction(byte id) { var model = new MyModel { ObjectProp1 = "Some text" }; return View(model); } [HttpPost] public ActionResult MyAction(byte id, FormCollection form) { // TODO: DB insert logic goes here var result = ...; return Json(result); } I am returning a partial view that looks something like this: <% using (Html.BeginForm("MyAction", "MyController")) {%> <%= Html.ValidationSummary(true) %> <h3>Create my object</h3> <fieldset> <legend>Fields</legend> <div class="editor-label"> <%= Html.LabelFor(model => model.ObjectProp1) %> </div> <div class="editor-field"> <%= Html.TextBoxFor(model => model.Size.ObjectProp1) %> <%= Html.ValidationMessageFor(model => model.ObjectProp1) %> </div> div class="editor-label"> <%= Html.LabelFor(model => model.ObjectProp2) %> </div> <div class="editor-field"> <%= Html.TextBoxFor(model => model.ObjectProp2) %> <%= Html.ValidationMessageFor(model => model.ObjectProp2) %> </div> <p> <input type="submit" value="Create" /> </p> </fieldset> <% } %> Client side validation does not work in this case. What is more the script that contains validation messages also isn't included in the view that's returned. Both properties in my model class have Required and StringLength attributes. Is there any way to trigger client side validation in a view which has been loaded like this?

    Read the article

  • Asp.net MVC2 Custom jquery validation: client -side

    - by Lullaby
    Hi. I want to create a validation rule for 2 date-pickers (startDate less then endDate). I create a validation attribute: [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class DateCompareAttribute : ValidationAttribute { private const string _defaultErrorMessage = "'{0}' is less then '{1}'."; public DateCompareAttribute(string startDateProperty, string endDateProperty) : base(_defaultErrorMessage) { StartDateProperty = startDateProperty; EndDateProperty = endDateProperty; } public string StartDateProperty { get; private set; } public string EndDateProperty { get; private set; } public override string FormatErrorMessage(string name) { return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString, StartDateProperty, EndDateProperty); } public override bool IsValid(object value) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value); object startValue = properties.Find(StartDateProperty, true).GetValue(value); object endValue = properties.Find(EndDateProperty, true).GetValue(value); if (startValue.GetType() == typeof(DateTime?) && endValue.GetType() == typeof(DateTime?)) { var start = ((DateTime?)startValue); var end = ((DateTime?)endValue); return (start.Value < end.Value); } return false; } } and added ti to my Dto: [DateCompare("StartDate", "EndDate")] public class QualificationInput{...} I created a validator: public class DateCompareValidator : DataAnnotationsModelValidator { string startField; private string endField; string _message; public DateCompareValidator(ModelMetadata metadata, ControllerContext context , DateCompareAttribute attribute) : base(metadata, context, attribute) { startField = attribute.StartDateProperty; endField = attribute.EndDateProperty; _message = attribute.ErrorMessage; } public override IEnumerable<ModelClientValidationRule> GetClientValidationRules() { var rule = new ModelClientValidationRule { ErrorMessage = _message, ValidationType = "dateCompare" }; rule.ValidationParameters.Add("startField", startField); rule.ValidationParameters.Add("endField", endField); return new[] { rule }; } } And registered it in Global.asax.cs in Application_Start(): DataAnnotationsModelValidatorProvider .RegisterAdapter(typeof(DateCompareAttribute), typeof(DateCompareValidator)); In MicrosoftMvcJQueryValidation.js I have made this changes: switch (thisRule.ValidationType) { ..... case "dateCompare": __MVC_ApplyValidator_DateCompare(rulesObj, thisRule.ValidationParameters["startField"], thisRule.ValidationParameters["endField"]); break; ..... } .... function __MVC_ApplyValidator_DateCompare(object, startField, endField) { object["startField"] = startField; object["endField"] = endField; } jQuery.validator.addMethod("dateCompare", function(value, element, params) { if ($('#' + params["startField"]).val() < $('#' + params["endField"]).val()) { return true; } return false; }, jQuery.format("Error")); But it doesn't work :( no client side validation on this type of rule (the others type like required works fine) What I'm doing wrong?

    Read the article

< Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >