Welcome Guest, Not a member yet? Register   Sign In
set_value not pulling through results with variable based field name.
#1

[eluser]danmatthews[/eluser]
Hi all,

I'm using a while() loop to create a set of 8 exact same sets of form elements for a survey building application. The while loop uses a counting variable "$i" to keep track of the field number. Posted a sample from the view file below.
Code:
&lt;?php $i =1; while($i <= 8) : ?&gt;
    
<div class="field-container">

<h2>Field #&lt;?=$i?&gt;</h2>
    

    <div class="field-field-container">

        <label for="">Field Name</label>
        
        &lt;?php echo form_input("fields[$i][name]"); ?&gt;
        
        <div class="field-description">All lowercase, only hyphens (-) and underscores (_) allowed please!</div>
    </div>

The problem i'm having while using the form validation class is that when using set_value() to retrieve the submitted value, i'm trying to tie the field name with the $i variable like so:
Code:
&lt;?php echo form_input("fields[$i][name]", set_value("fields[$i][name]"); ?&gt;

But it doesn't seem to be picking it up! It's acting like a major block to my applications' development. Just wondered if this was something i was doing wrong, if it's not possible at all, or if this is a bug.

Cheers.
#2

[eluser]Brad K Morse[/eluser]
Are you setting up the validation rules within your controller? http://ellislab.com/codeigniter/user-gui...ationrules
#3

[eluser]danmatthews[/eluser]
I should be, does a validation rule HAVE to be set in order for set_value() to replace the data? What happens in the situation where, say, you don't need to do any validation on a field, but validation fails on other fields around it and it has to re-load the form view?
#4

[eluser]AlunR[/eluser]
[quote author="danmatthews" date="1307365267"]I should be, does a validation rule HAVE to be set in order for set_value() to replace the data? What happens in the situation where, say, you don't need to do any validation on a field, but validation fails on other fields around it and it has to re-load the form view?[/quote]

set_value() only works when an item has been validated. I think this is wrong as the two are 2 unrelated things but...

So you have 2 options.

1. Set a validation of TRIM on each element

2. Follow these instructions: http://ellislab.com/forums/viewthread/159535/#775628

I've done the latter on all my projects.
#5

[eluser]Brad K Morse[/eluser]
You are still required to set a non-required field's rules up in the controller, you will just leave the parameters blank, like this:

Code:
$this->form_validation->set_rules('name_of_field', '', '');

Be sure to add all fields you want the user's data to be retained in case validation does not pass, even the fields that are not required.

Check out this tutorial http://jrtashjian.com/2009/02/simple-log...deigniter/, it shows you how to create a login page but pay attention to the validation part of it.
#6

[eluser]danmatthews[/eluser]
Thanks guys, that sorted it, much much appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB