Closed Thread Icon

Topic awaiting preservation: How would you (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12149" title="Pages that link to Topic awaiting preservation: How would you (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: How would you <span class="small">(Page 1 of 1)</span>\

 
bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-29-2002 23:57

Alright so I hate creating forms so I'm wrting a class in PHP to take care of all the dirty work for me.
I'm running into one problem.

Here's the deal I have an array of all the form elements that I want to print out into a table. I want the user to be able to decide how many columns wide the table would be (default would be 2). I'm figuring most form elements can be 1 table cell wide, however text area's need to span at least 2 of the cells (Since I'm creating this I'm figuring textareas can span all columns).

Now the hard part is that I need to figure out how to loop through the array of elements and basiclly map them to a table cell. But I need to do it so that I get a nice table and nothing breaks.

Am I making sense here?
I've got a couple of ways I'm trying to go about it but they all seem clunky.



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-30-2002 00:43

Could you post the format of the array?

-jiblet

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-30-2002 03:27

well it's actually an 2D array.

It's basically it's a numbered array of hash's

$elm[0] = array("name" => "form_field_1", "type" => "text", "value" =>"whatever");
$elm[1] = array("name" => "form_field_2", "type" => "radio", "value" =>"whatever");
$elm[2] = array("name" => "form_field_3", "type" => "textarea", "value" =>"whatever");

just to make it simple to loop through and write the form fields, if I didn't want it in a table I could just do this

foreach ($elms as $var) {
if ($var['type'] != "textarea") {
echo "<input type=\"$var['type']\" value=\"$var['value']\" name=\"$var['name']\">";
} else {
echo"<textarea name=\"$var['name']\">$var['value']</textarea>";
}
}

there's more to each hash but this should give the idea.



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 03-30-2002 04:48

Are any table cells supposed to be reserved for labels?

Are the form elements supposed to get mapped into the table from left to right in the order of the array filling up cells as completely as possible? If so, what you need is a variable that keeps track of how many columns are left in the current row.

code:
//$numCols = the number of desired columns
$remaining = $numCols
foreach($elms as $element) {
$formField = FORM ELEMENT FROM YOUR EXISTING CODE
//not enough columns? Start a new row and reset column counter.
if ($remaining - $element['cols'] < 0) {
while ($remaining > 0) {
print "<td>&amp;nbsp;</td>";
}
print "\n</tr><tr>\n";
$remaining = $numCols;
}
if ($element['cols'] > 1) $colspan = ' colspan="'.$element['cols'].'"';
else $colspan = '';
print "<td$colspan>$formField</td>";
$remaining -= $element['cols'];
}



Is this kind of what you mean?

-jiblet


[This message has been edited by jiblet (edited 03-30-2002).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-30-2002 07:41

Ahh very nice, that's exactly what I mean.
I didn't think of it as how many columns left, sometimes it's all about the mindset.

Thanks!




.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

[This message has been edited by bitdamaged (edited 03-30-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu