Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Problem to retrieve the number of input fields in a page
#1

[eluser]Pr0v4[/eluser]
Hi guys, I'm writing you to have a bit of help to understand how to know the amount of input fields present in a page...

Properly because my view page, or better the form with the input fields, it's been built dynamically from a database,it's impossible for me know in advance how many input fields i've got (or better I don't know how to find them...).

I know that something like that it's very simple to have from jQuery. like:
Code:
$(input['checkbox']).length()
for example

But it's present in CI a function or some helper that let us know something like that???

If u need to see the code and how i've developed it, just ask!
#2

[eluser]überfuzz[/eluser]
Do you use method="post"?
Code:
$field_count = count($_POST);
#3

[eluser]Pr0v4[/eluser]
Yes actually i am using the method post, and the solution that you shown me it's great, sorry for this lack but i don't have a great PHP experience and for that sometime I have some silly questions Big Grin

BTW thinking about that yesterday night, i got an another idea. For example is possible understand how many checkbox are actually checked??? Taking again the jQuery framework doing something like this:

Code:
$(input['checkbox']:checked).length()

Probably in CI i should do a loop that go through ALL the input elements, maybe:
Code:
$field_count = count('post'); //should work like that as well, or not?
foreach($field_count as $checkbox){
    if(isset($checkbox) || $checkbox == 'active'){//I use active because is the value attributs of my checkbox. Is that right used like that?
       /*
          And now i should create a new array to save all the field that has been selected
          in this example my form will have Only checkbox field
       */
    }
}

Actually I'm not even sure about my loops... It's like that that I can check if that field has got a 'selected' status??

Thanks in advance fot all the useful advices!
#4

[eluser]Pr0v4[/eluser]
Ok, I've tried for few days some different solutions but no one looks work properly.

All that I would like to do is retrieve a test from my db (np), show the test (np) and insert a new mark test (and here at the moment i cannot success...)

My idea is something produce this kind of HTML:

Code:
<form method="post" action="http://localhost:8888/TestYourSkills/tysk/ci/index.php/test/insert">
<div id="quest_field_1" class="quest_field">
<p>Question 1: </p>
&lt;input type="hidden" value="quest_field_1" name="quest_field_1"/&gt;
<label for="ans_field_1">yes</label>
&lt;input id="ans_field_1" type="checkbox" value="1" name="ans_field_1"/&gt;
<label for="ans_field_2">no</label>
&lt;input id="ans_field_2" type="checkbox" value="2" name="ans_field_2"/&gt;
</div>
<div id="quest_field_2" class="quest_field">
<p>Question 2: </p>
&lt;input type="hidden" value="quest_field_2" name="quest_field_2"/&gt;
<label for="ans_field_3">maybe</label>
&lt;input id="ans_field_3" type="checkbox" value="3" name="ans_field_3"/&gt;
<label for="ans_field_4">probable</label>
&lt;input id="ans_field_4" type="checkbox" value="4" name="ans_field_4"/&gt;
</div>
&lt;input type="submit" value="Submit Test" name="submit"/&gt;
&lt;/form&gt;

When my user will press the submit button i would like insert on my db only the checkbox that have been checked. with the solution
Quote:$field_count = count[$_POST];
I've ALL the value that are been sent, but i don't wont that...

I'm sorry to bother you guys, but to realize my application I have to define this behavior, and also it's the first time that i find myself fighting with a proper form, until now I always need them to create mail form Big Grin

Also I would like to check that for wach question, the user can send only one answer...

Can you at least give me something to read???
Thanks in advance!
#5

[eluser]metaltapimenye[/eluser]
Code:
$(input['checkbox']).length()

.. dude, is it JQUERY are we talk about?
#6

[eluser]Pr0v4[/eluser]
[quote author="metaltapimenye" date="1259142218"]
Code:
$(input['checkbox']).length()

.. dude, is it JQUERY are we talk about?[/quote]

Hey buddy if you read properly the post you'll notice that i specified that was jQuery
[quote author="Pr0v4" date="1258855204"]
I know that something like that it’s very simple to have from jQuery. like:
Code:
$(input['checkbox']).length()

for example

But it’s present in CI a function or some helper that let us know something like that???
[/quote]

And i was looking to a function in CI to solve that...

BTW thanks for the help!
#7

[eluser]Unknown[/eluser]
Thank your for sharing this wonderful story. I find your post very informative.
I am very excited to be a part of this Forum and look forward to bringing Value to it
#8

[eluser]Flemming[/eluser]
checkboxes do not show up in $_POST data unless they have been checked. So does that help you at all?

In order to stop a user checking more than 1 box you can use jquery to unselect ALL the checboxes first and then check the one which has been clicked
#9

[eluser]Pr0v4[/eluser]
[quote author="Flemming" date="1259171769"]checkboxes do not show up in $_POST data unless they have been checked. So does that help you at all?

In order to stop a user checking more than 1 box you can use jquery to unselect ALL the checboxes first and then check the one which has been clicked[/quote]

Your help it's been so helpfol that now I'm able to insert the query!

Now i've only to show the test for each user, but this is something different Big Grin
#10

[eluser]Flemming[/eluser]
excellent! Smile

good luck!




Theme © iAndrew 2016 - Forum software by © MyBB