[FX.php List] Problem re-submitting checkboxes to FM7
DC
dan.cynosure at dbmscan.com
Thu May 11 14:24:49 MDT 2006
Hi Gerry,
Thanks for posting that code. it looks like a nice way to build a select
form element. Please forgive me if I consider it a teachable moment!
Here's a tidy version of your code. I hope you take it as a compliment
that I've re-written it to better PHP usage - concise, clear.
The changes I made are:
1) consolidate variables - using $list
2) nl2br() function - replaces str_replace()
3) removed $key in foreach - not used in code, don't use it
4) condensed the strlen(strstr()) nested functions and $select and
$theresult variable checking code to one line with PHP's alternative
"if" syntax - this one is a little weird the first time you see it, but
it's just like the if() function in FMP scripts. If the expression in
parens evals to true you get the first string, if false, you get the
second - then the string is stuffed into the $select variable. I like
this technique because it is very tidy. Oh, yeah, the ' ' . prepend
thing is to trick the strpos() function into NOT returning 0 for the
string found at first character position - see PHP docs for more.
<?php
$list = $recordData['AssignedTo'][0];
echo nl2br($list).'<BR>';
?>
<select name="AssignedTo" size="3" multiple>
<option value=""></option>
<?php
//The full list of items
foreach ($searchUserResult['data'] as $searchUserData){
//identify the first item to check
$searchString = $searchUserData['NameFullLastFirst'][0];
//checking to see if I have a match
$select = (strpos(' '.$list,$searchString)) ? ' selected': '';
//echo $searchString.$select.'<BR>';
//sending the data to the page
echo '<option
value="'.$searchString.'"'.$select.'>'.$searchString.'</option>';
}
?>
</select>
HTH,
dan
gerry.charest at agfa.com had written:
> William
>
> The following represents pull down menus but I think the issue is the
> same with check boxes. You need to identify form the list of potential
> items the ones that are selected or entered in the database. Then mark
> them appropriately in the html. In the example I have my list values
> coming from another query "searchUserResult" and the recordData
> containing the field with multiple values. While not exactly what you
> are looking for it might get you started.
>
> Best regards
> Gerry
>
>
> <?php
> $newAssignedTo = str_replace("\n", '<BR>', $recordData['AssignedTo'][0]);
> echo $newAssignedTo.'<BR>'; ?>
> <select name="AssignedTo" size="3" multiple>
> <option value=""></option>
> <?php
> $list = $recordData['AssignedTo'][0];
>
> foreach ($searchUserResult['data'] as $key => $searchUserData){//The
> full list of items
> $searchString = $searchUserData['NameFullLastFirst'][0];//identify the
> first item to check
> $theResult = strlen(strstr($list,$searchString)); //checking to see if I
> have a match
> if ($theResult >0){
> $select = ' selected';
> }
> else {$select = '';}
> //echo $searchString.$select.'<BR>';
> echo '<option
> value="'.$searchString.'"'.$select.'>'.$searchString.'</option>';//sending
> the data to the page
> }
> ?>
> </select>
>
> Inactive hide details for "William Akey" <wcakey at hotmail.com>"William
> Akey" <wcakey at hotmail.com>
>
>
>
>
>
> *"William Akey" <wcakey at hotmail.com>*
> Sent by: fx.php_list-bounces at mail.iviking.org
>
> 05/11/2006 03:26 PM
> Please respond to "FX.php Discussion List"
>
>
>
> To: "FX.php Discussion List" <fx.php_list at mail.iviking.org>
> cc: (bcc: Gerry Charest/MJVYN/AGFA)
> Subject: [FX.php List] Problem re-submitting checkboxes to FM7
>
>
>
> A while ago, there was some good discussion about how to properly display a
> series of checkboxes on a web page. Thanks to those discussions and the use
> of the explode() and in_array() functions I have been able to get this
> working correctly.
>
> What I cannot get to work correctly is the return of the edited checkbox
> data to the FM7 database. If I set up the input elements as:
>
> <input type="checkbox" name="FieldName[]" value="nine" checked >
> <input type="checkbox" name="FieldName[]" value="ten" checked >
>
> and then use implode("\n", $FieldName) before submitting it back to the
> database with FMEdit(), I get a PHP bad argument warning for the implode()
> function and the data in FileName in the database is erased. If I do not use
> implode() before submitting $FieldName, then FieldName in the database ends
> up with the word "Array" in it and the other values are gone.
>
> If I use FieldName in the input tag, without the "[]", and do not use
> implode(), then only the last checked value gets submitted to the database
> and the others are deleted.
>
> It seems that using FieldName[] in the input tag and implode("\n",
> $FieldName) in combination should work, but it doesn't. So, what am I doing
> wrong and how do I get this to work correctly??
>
> Thanks for any help you can offer.
>
> William
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list