dynamic form checking PROBLEM

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brainpulse
Forum Newbie
Posts: 2
Joined: Thu Jan 19, 2006 8:04 am

dynamic form checking PROBLEM

Post by brainpulse »

Well i'm new to php and i want to do the following:


I have a form woth 32 fields and i want to check if this fields has values entered.

So, i think to use a for loop and to constract the checking value dynamically.

the posted fields has the same name except two characters - the numbers that defines the field indivitually.
i.e. 10-0?-001-q?

I use the following script to generate the id's of posted fields.

Code: Select all

for ( $i = 1; $i <= 32; $i ++) {
if ($i > 9) {
$source="10-".$i."-001-q".$i;
}else{
$source="10-0".$i."-001-q".$i;
}

After that ... and there is the problem.... i create a string as follows

Code: Select all

$constract= "(isset(\$_POST['".$source. "'])) ? \$_POST['".$source."'] : \"\" ;" ;


With that way i suppose that i can check if the field has data in it or not.

Code: Select all

if (!$constract) {

echo "no data for field:" . $source;
}else{ 
echo "Field: " . $source . " has the following data: " . $constract; 
}


The problem here is that $constract variable does not store the value of the posted field but stores the hole string ....

Code: Select all

(isset($_POST['10-01-001-q1'])) ? $_POST['10-01-001-q1'] : "" ;

Code: Select all

(isset($_POST['10-02-001-q2'])) ? $_POST['10-02-001-q2'] : "" ;

.
.
.

I want to store the value of the posted field ..... and not the hole string ...


Can anyone help me ????
Thanks
sorry for my english
Last edited by brainpulse on Thu Jan 19, 2006 10:02 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Please edit you post and use the PHP code tags Image
brainpulse
Forum Newbie
Posts: 2
Joined: Thu Jan 19, 2006 8:04 am

????

Post by brainpulse »

what do you mean ?????
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply