Login Retreive lost passwordRegister
Search

Forum Index / Feedback / arrays in the POST

[ This topic is solved ]

  Martijn Korse 07 July 05 / 14:27  
Can FormHandler handle, process, validate, etc. fields that create arrays after being posted.

Like

<input type="text" name="bla[1]">
<input type="text" name="bla[2]">

<input type="checkbox" name="id[]">
<input type="checkbox" name="id[]">
<input type="checkbox" name="id[]">

?

  Teye Heimans (Founder) 07 July 05 / 17:01  
 Quote: Martijn Korse
 
Can FormHandler handle, process, validate, etc. fields that create arrays after being posted.

Like

<input type="text" name="bla[1]">
<input type="text" name="bla[2]">

<input type="checkbox" name="id[]">
<input type="checkbox" name="id[]">
<input type="checkbox" name="id[]">

?


No, FormHandler cannot (yet) handle arrays as names, but the second example you gave (checkboxes) is build in and will be generated when you give an array as value to the checkbox method.

  Martijn Korse 07 July 05 / 17:28  
 Quote: Teye Heimans
 
[...]
the second example you gave (checkboxes) is build in and will be generated when you give an array as value to the checkbox method.


Ah, but i guess something like this:

<input type="checkbox" name="id[5]">
<input type="checkbox" name="id[21]">

is not possible ... or is it?

It is particularly usefull when working with database-data. That's why i'm asking it (and why i consider it a vital function)

  Teye Heimans (Founder) 08 July 05 / 11:14  
This is possible:


<?php

$itemsFromDB 
= array(
  
=> "item1",
  
=> "item2",
  
=> "item3",
  
=> "item4"
);

$form->checkBox("Items""items"$itemsFromDBtrue);

/*
Now the user can select a number of checkboxes. The one he selected will be in the array of the field's result. e.g.:
*/

function doRun$data ) { 
    
print_r($data["items"]);
    
// prints somehting like array( 1, 4, 9 )
    // depending on what the user selected :-)
}
?>


  glenn 20 November 06 / 13:19  
Changed at 20 November 06 / 13:38
How can i do this with a textfield? already before the form is printing?

I want this because i want to use it by this webpage:
http://d3dgroep2.glrdmd.eu/album.php


I have now this script

<?php
include("FH3/class.FormHandler.php");

$itemsFromDB = array(
  
=> "item1",
  
=> "item2",
  
=> "item3",
  
=> "item4"
);
$form =& new FormHandler();

//$form->checkBox("Items", "items", $itemsFromDB, NULL, true);
$form -> setValue("items""Enter your name...");
$form->textField"Items""items"FH_STRING2040);

// button for submitting
$form->submitButton();

// set the 'commit-after-form' function
$form->onCorrect('doRun');

// display the form
$form->flush(); 

/*
Now the user can select a number of checkboxes. The one he selected will be in the array of the field's result. e.g.:
*/

function doRun$data ) {
    echo 
"test";
    
print_r($data["items"]);
    
// prints somehting like array( 1, 4, 9 )
    // depending on what the user selected :-)
}
?>

  Teye Heimans (Founder) 20 November 06 / 15:35  
it is not possible to use "array" fields with textfields. Sorry, FH does not support that...

  glenn 24 November 06 / 08:38  
ok thx for the reply

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license