Welcome Guest, Not a member yet? Register   Sign In
Validation of listbox, checkbox groups and reselect multiple values using set_select, set_checkbox / Sol: Array to strin
#11

[eluser]vadivelan[/eluser]
Welcome Thomas!
Best Wishes
Velan
#12

[eluser]Dan Murfitt[/eluser]
Thanks for posting this. I've found that the default value works well, the only problem I'm having now is with the error message. If you set the rule for the (say) multiple checkbox field to 'required' then the default error message needs changing. So, I did this with:

Code:
$this->validation->set_message('required', 'Please check %s');

This can then be adapted by entering the information in the fields array. However, this seems to change the message for all other fields apart from the checkboxes. I then tried setting a callback to validate checkboxes instead of using the 'required' rule (so I could set the error message from within the callback function), however, the callback function only seems to run when at least one of the checkboxes is checked. Does anyone have a work around for this?

Many thanks
#13

[eluser]Dan Murfitt[/eluser]
Looking closer, the error message returned for the checkbox array with the 'required' rule was coming from $lang['isset'] rather than $lang['required'] (which the other fields with 'required' were) (see http://codeigniter.com/wiki/Validation/). This means that to change the error message for the checkbox array with the validation fix and 'required' rule you need to use something like:

Code:
$this->validation->set_message('isset', 'Please select at least one %s');
#14

[eluser]The Wizard[/eluser]
Hello Friends,

how does it look like when we generate dropdowns with the form helper?

are we able to add validation to them?
#15

[eluser]drewbee[/eluser]
I personally vote this going in as a bug. I find (at least myself) every 2 to 3 forms i build out of say 5, require the use of an array data being passed. I was really surprised this wasn't standard functionality. Thanks for the extension. I look forward to this being standard functionality Smile

This also works with the 'set default values' hack that has been going around for CI's Validation library. I know, it probably doesn't belong there. I just couldn't justify a hole new helper just for one function.
#16

[eluser]The Wizard[/eluser]
yeah i think it should be standart behavior tooSmile
#17

[eluser]Derek Jones[/eluser]
Hey gang, there have been some significant changes to the validation library I thought everyone here would be interested in.
#18

[eluser]The Wizard[/eluser]
thank godSmile

yeah, ill look at it
#19

[eluser]drewbee[/eluser]
Chamone!!!

::goes and grabs a full jar of cookies::
#20

[eluser]kamal1976[/eluser]
Hello,
I made those changes in the validation class but still I am getting following notices for Check Box and List Box with multiple values selected.

A PHP Error was encountered

Severity: Notice

Message: Undefined index: cash_codes

Filename: libraries/MY_Input.php

Line Number: 132


My Smarty template code for the check box is
<input type="checkbox" name="cash_codes" id="cash_codes" <!--[if $CASH_CODES_ONLY == "on" ]-->checked<!--[/if]-->>Cash Codes Only
//This is my second check box
&lt;input type="checkbox" name="summary_flag" id="summary_flag"&gt;Summary</td>

Both the check boxes are single and independent.


My code for the list box with multiple selection is as given below.

<select name="txn_code_list[]" id="txn_code_list" value="" multiple="multiple" size="15" style="width:200px">
&lt;!--[foreach item=RESULT from=$RESULTS]--&gt;
<option value="&lt;!--[$RESULT.transaction_code]--&gt;">&lt;!--[$RESULT.transaction_code]--&gt; &lt;!--[$RESULT.description]--&gt;</option>
&lt;!--[/foreach]--&gt;
</select>

It gives following notice.
A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/MY_Validation.php

Line Number: 552

This is my code in controller

$product_code = $this->input->post('product_code');
$summary_flag = $this->input->post('summary_flag');
$user_id_list = $this->input->post('user_id_list');

Can you please guide me how to solve this errors with out suppressing them.

Thank you...




Theme © iAndrew 2016 - Forum software by © MyBB