CodeIgniter: set_checkbox problem - validation

I seem to be running into something really nasty:
I have a form which contains a group of checkboxes.
I have set up validation rules for my form, and just added an empty one
for my checkbox group. However, after validating my form and giving an error,
it only rechecks the last one in the group that was selected. This is just
driving me nuts, since the user will never notice it was unchecked!
for now, before building up the system, I just hardcoded the form to check if it works
how I want it to work.
<fieldset>
<legend>Locaties veldwedstrijden</legend>
<?php echo form_checkbox('locatie','oudenaarde', set_checkbox('locatie','oudenaarde'));?>3-7-2011 te Oudenaarde <br />
<?php echo form_checkbox('locatie','arendonk', set_checkbox('locatie','arendonk'));?>31-7-2011 Arendonk<br />
<?php echo form_checkbox('locatie','westdonk', set_checkbox('locatie','westdonk'));?>11-09-2011 Westhoek – MERKEN<br />
</fieldset>
It also has this validation rule in it:
array('field' => 'locatie','label' => '','rules' => ''),
Can anybody tell me what I'm doing wrong? I read the whole manual, but I can't
find the slightest hint of what might be wrong with this code...

You're using a checkbox like a radio button. No matter how many checked checkbox, they're all named locatie, php will only see one value.
If you wanted to save multiple values from the checkbox, you'd either need to use a different name for each checkbox (locatie1, locatie2, locatie3) or use a php style name array (locatie[]). I'm not sure for the latter that the CI form helper function will work properly with that style of naming though.

Related

How can I use Spring MVC "form" tag instead of my "input" tags?

What I have:
I have a generic JSP page that is used throughout my application for displaying certain entities. The code that I am interested in goes like this:
<form:form modelAttribute="object"/>
<core:forEach items="${sections}" var="section" varStatus="itemStat">
<core:forEach items="${section.fields}" var="fieldDef">
<form:input path="${fieldDef.fieldName}"/>
</core:forEach>
</core:forEach>
<form:form>
For each section, and for each field in that section, I have an input having the path fieldName, which is what I want to display from each field.
What I want:
I would like instead of the input to be a simple text, like a label.
What I have tried:
I am most certain that I can do it somehow with <form:label> but I can't really make it work. Making a <form:label path="${fieldDef.fieldName}" /> just tells the browser for which field I need the label, but doesn't get the actual value from it.
I have also tried something like ${object.fieldDef.fieldName}, but in order for this to work I would have to first analyze the value of ${fieldDef.fieldName}, which would give me the name of the column, and then do a ${object.column}, but column being a variable I haven't been able to make this work in any way.
Alternative:
An alternative would be to just make the inputs as disabled and remove the border with CSS, but that would be a dirty way and from what I saw it is also tricky for IE different versions. I am sure that I can handle it directly.
I am a little intrigued by the fact that <form:input path="..."> puts into the input what it finds corresponding to that path (same goes for other form elements), but with label it works different.
So, what I want is basically simple, but I haven't managed to find a way. If someone could shed some light, that would be great. Thanks in advance !
You could look into the spring bind tag. I haven't tried using it before but this may work for you, in place of the input tag
<spring:bind path="fieldDef.fieldName">
${status.value}
</spring:bind>
reference: http://static.springsource.org/spring/docs/1.1.5/taglib/tag/BindTag.html
Instead of
<form:input path="${fieldDef.fieldName}"/>
use
<c:out value="${fieldDef.fieldName}"/>
It would display whatever value is there instead of creating a input field. Hope this helps you. Cheers.
Using the spring form tab, one option would be to use
<form:input disabled="true" path="${fieldDef.fieldName}"/>
To further make it not look like an input you could use CSS to style it to your preference.
Some css styles you could use:
background-color:#EEEEEE;border: 0px solid;
Update:
You could look into the spring bind tag. I haven't tried using it before but this may work for you, in place of the input tag
<spring:bind path="fieldDef.fieldName">
${status.value}
</spring:bind>

How to recognaize which ajax form it is in Django?

I have view which takes care of all the Ajax submits from the client side. And to differentiate them by I uses different submit button names such as this one
<input type="submit" value="Send" name="send_message">
Suggested from this question.
The only problem is that from the view side it doesn't seems to carry the name to the server side so I cannot use the following if-statement
if 'send_message' in request.POST:
It works if I send it normally with page fresh. But I want to use it with Ajax.
I came up with a hack that you can add this name with jQuery. Simply by after serializing() your data you then concatenate the name attribute by data += "&send_message"
Then the if statement will work. But it doesn't seems so clean. So I wonder if there's a better way to handle this? Or should I make different views to handle the different Ajax calls I have?
You really should post each form to a different URL.
If not, you could add a hidden input with the name of the form as the value.
<input name="form_name" type="hidden" value="form_1" />
views.py:
form_name = request.POST['form_name']

Grails formRemote

I have DateFrom and DateTo fields. I want to submit those data to action which will do some business logic but nothing changes on the original GSP, and nothing is updated. How do I manage this? I've tried this:
<g:formRemote name="formName" url="[action: 'myAction']">
Everything is fine but except my action tries to render myAction.jsp.
This is a great place to read how it works.
Basically you need to specify what controller as well:
<g:formRemote name="formName" update="updateMe" url="[controller: 'controller', action:'myAction']">
The "updateMe" is the id of an html-object, preferably div, that you want to alter after submit (but it's not mandatory). It also uses the actionName.gsp to "supply" the answer, this is why you need to have this page create as well.
Remote forms are a bit tricky in the beginning, but they're super simple once you get a hang of it!
This is how I did it:
GSP:
<g:formRemote name="formName" update="updateMe" url="[controller: 'controller', action:'myAction']">
<div id="updateMe">
<g:render template="updateTemplate"/>
</div>
Action:
...
render template:"updateTemplate"
updateTemlate and updateMe div are both empty.
If you have better solution please tell me.
you can use remoteFunction
you need to write submit button inside form and then after it will fire action and some changes shown into div..

Using Joomla 1.7 generic categories functions

Since 1.6, I believe, there's a generic way to use 'categories' in your own created components. The default Joomla components also use this. For example: the contacts, newsfeeds and weblinks components all use the generic com_categories functionality to achieve categorized content.
Currently I'm creating a component which also has categories so I'd like to use the generic Joomla category functions to achieve this.
The status: Currently I've got the following:
I've got a submenu 'categories' in my component which links to the generic categories component which some extra options. The options are there so the page will be redirected back to my component on save. This was pretty easy! But..
My problem: Now I'd like to add specific fields to my category, let's say: 'Category Moderator'.
So I've walked to the code of com_categories and in the following file 'administrator\components\com_categories\models\category.php' there is code (line 270) to look for specific component code, like the following:
// Looking first in the component models/forms folder
$path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/models/forms/$name.xml");
So the components looks (in my case) in the folder: administrator/components/mycomponent/models/forms/category.xml for specific component info.
Now, in the default category.xml of com_categories there's information about the edit screen, like the following:
<field
name="title"
type="text"
label="JGLOBAL_TITLE"
description="JFIELD_TITLE_DESC"
class="inputbox"
size="40"
required="true"/>
So the title of the category is apparantly required..
So I thought I add a line to this file:
<field
name="moderator"
type="text"
label="JGLOBAL_MODERATOR"
description="JFIELD_MODERATOR_DESC"
class="inputbox"
size="40"
required="true"/>
Except that's not enough to add the input..
So I've looked in the administrator/components/com_categories/views/category/edit.php template for hints, how to achieve this. But there's no code to add specific inputs for my component (or I'm wrong ;))..
Fields are added pretty specific like:
<li><?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?></li>
I've also looked if I can overide the edit.php somehow, but unfortunately I haven't found it..
Short: Anyone knows how to add generic fields to the category edit page?
You can do it by using plugins ( you can take a look at the built-in user profile plugin for an example: /plugins/user/profile ). But if you want to add a "Category Moderator", I think you could achieve it using ACL.

Codeigniter validation

Based on the backend data i may have n number of items displayed along with the check box and textarea for selecting and give commnet on the page and there is also a option given to the user to remove the items based on the requirements. I need to set a validation like atlease one item is required.
Since its number is based on the query dont know how to set the validation.
It's hard to say without a bit more detail, but in general if you have a set of checkboxes and you want to make sure at least one is checked you could do this in your HTML:
<p><input type="checbox" name="my_field_name[]" value="item1" />Item 1</p>
<p><input type="checbox" name="my_field_name[]" value="item2" />Item 2</p>
<p><input type="checbox" name="my_field_name[]" value="item3" />Item 3</p>
and just set a rule that "my_field_name" is a required field. That's assuming it works for you to have the values returned in one array like that.

Resources