This topic is locked

Multi value Form

2/3/2012 2:08:48 AM
PHPRunner General questions
S
Sergej author

I have added multi value field on one form and at first it put all the values inside one field separated by coma. Then i used Before record aded event and modified code

it worked fine but it populated table with only RecievingCountry values - which were in multivalue field - all other values were empty. How should i add inside the loop command to populate all other values also? - Bold lines are were my try but it didn't work! Please help!!!
THNX A LOT!!!!

if ($values["RecievingCountry"])
{
$arr = explode(",",$values["RecievingCountry"]);

$id = $values["id"];

// This is the name of the multi check box or
// list select field, its value becomes $arr
for ($i=0;$i<count($arr);$i++)
{
$strInsert = "insert into RefferedWorkForm (RecievingCountry,) values ('".$arr[$i]."')";

$strInsert = "insert into RefferedWorkForm (id) values ("id")";
// add more fields from the add page to be inserted into database
db_exec($strInsert,$conn);
}

header("Location: RefferedWorkForm_list.php");
// Exit and Redirect to the list page after updating database
exit();
}
// Place event code here.

// Use "Add Action" button to add code snippets.
return true;

D
danaci 2/3/2012

$strInsert = "insert into RefferedWorkForm (id) values ('".$id."')";

S
Sergej author 2/3/2012



$strInsert = "insert into RefferedWorkForm (id) values ('".$id."')";



thank you danaci - the error is gone but now i get only empty fields in the table ...

D
danaci 2/3/2012

try this.

$strInsert = "insert into RefferedWorkForm (id) values (".'$id'.")";

S
Sergej author 2/3/2012



try this.

$strInsert = "insert into RefferedWorkForm (id) values (".'$id'.")";



Thank you - will try - btw do you think $id variable is properly initialized?

S
Sergej author 2/3/2012

[quote name='Sergej' date='03 February 2012 - 03:41 PM' timestamp='1328272917' post='64110']
Thank you - will try - btw do you think $id variable is properly initialized?
it works GREAT! thank you!

S
Sergej author 2/3/2012

would it be posible to do this with several multiple fields on a same form - would it be nested if's or...

D
danaci 2/3/2012

$strInsert = "insert into RefferedWorkForm (your tables fields)

values (" your form fields")";

$strInsert = "insert into RefferedWorkForm (id,name,secname, etc.) values(".$values["name"],$values["secname"],$values["other"].")";

S
Sergej author 2/6/2012

thank you
but how should i put if condition for multiple fields...

should i listed it one by one
if ($values["field1"])
{
$arr = explode(",",$values["field1"]);

$id = $values["id"];

}

if ($values["field2"])

{
$arr = explode(",",$values["field1"]);

$id = $values["id"];

}

D
danaci 2/6/2012

[quote name='Sergej' date='06 February 2012 - 07:16 AM' timestamp='1328512579' post='64143']

thank you
but how should i put if condition for multiple fields...

should i listed it one by one
if (length($values["field1"])>0)
{

....

}