On Aug 22, 5:09 pm, desbest <afanintheho...@gmail.com> wrote:
> How do I use AjaxRequest to POST checkboxes which is an array, not a
> variable?
> [code]
> =====================================
> <script type="text/javascript">
>
>         function addEvent(day, month, year, body, involved) {
>                 if(day && month && year && body && involved) {
>
>                          //alert('Add Event \n Day: '+day+'\n Month: 
> '+month+'\n Year:
> '+year+'\n Involved: '+involved+'\n Body: '+body);
>
>                         new Ajax.Request('rpc.php', {method: 'post', postBody:
> 'action=addEvent&d='+day+'&m='+month+'&y='+year+'&involved='+involved
> +'&body='+body+'', onSuccess: highlightEvent(day)});
>
>                         $('evtBody').value = '';
>                 } else {
>                         alert('There was an unexpected script error.\nPlease 
> ensure that
> you have not altered parts of it.');
>                 }
> </script>
> ========================================
> [/code]
>
> It posts information using ajax but the rpc.php thinks that $involved
> equals 1.
> What it doesn't know is that $involved is an array, which when echoed
> reads Array because it has $involved[0] and $involved[1]. Below is
> rpc.php for a calendar script.
>
> [code]
> ===========================================
>                 $day = $_POST['d'];
>                 $month = $_POST['m'];
>                 $year = $_POST['y'];
>                 $body = $_POST['body'];
>                 $involved = $_POST["involved"];
>
>                 $howmany = count($involved);
>                 $timeStamp = mktime(0,0,0, $month, $day, $year);
>                 $bodyF = addslashes(trim($body));
>
>                 $addEvent = mysql_query("INSERT INTO event (body, timestamp, 
> userid,
> involved) VALUES ('$body', '$timeStamp', '$logged[id]', '$howmany')",
> $conn);
>
>                 $daidting = mysql_insert_id();
>                 $addInvolved = mysql_query("INSERT INTO involved (eventid, 
> userid)
> VALUES ('$daidting', '$howmany')", $conn);
>
>                 foreach ($involved as $f) {
>                 //echo $f."<br />";
>                 $addInvolved = mysql_query("INSERT INTO involved (eventid, 
> userid)
> VALUES ('$daidting', '$f')", $conn);
>                 }
>
> =======================
> [/code]

CGI has no concept of an array, even in POST. You either need to
serialise the array, or generate multiple instances of
"involved=whatever".

PHP has a nifty wrinkle whereby if a control in your page has a name
ending in '[]' then it will give you back an array.

BUT, where checkboxes are involved, I don't think an array is useful,
because the wonderful design of HTML returns absolutely nothing for an
unchecked box, so if you simply try to pass all the checkboxes back to
your CGI program you will get only the checked ones with no indication
of which boxes on the page they were.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to