Page 1 of 1

implode function not working

Posted: Fri Oct 03, 2008 9:26 am
by tonyledenko
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello,

I am trying to combine multiple values in a string to be submitted to a shopping cart. However, I can only get one of the two values to pass through to the cart. Any suggestions? Thanks in advance!

Code: Select all

<?php
if(isset($_POST['part'])) {
$checkbox = $_POST['part'];
$string = implode("^",$checkbox);
echo $string;
}
?>

Code: Select all

<form name='CartItem' action='https://www.ram-mount.com/RamCart/CartPutItem.php' method='POST'>
<input type='checkbox' name='part' value='RAM-VB-162'>
<input type='checkbox' name='part' value='RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: implode function not working

Posted: Fri Oct 03, 2008 9:37 am
by Kadanis
If I recall correctly you need to put square brackets on the name part of the form to specify an array

Code: Select all

 
<form name='CartItem' action='https://www.ram-mount.com/RamCart/CartPutItem.php' method='POST'>
<input type='checkbox' name='part[]' value='RAM-VB-162'>
<input type='checkbox' name='part[]' value='RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>
 

Re: implode function not working

Posted: Fri Oct 03, 2008 9:47 am
by tonyledenko
I tried your suggestion, and no values pass now. Any other suggestions?

<?php
if(isset($_POST['part'])) {
$checkbox = $_POST['part'];
$string = implode("^",$checkbox);
echo $string;
}
?>

<form name='CartItem' action='https://www.ram-mount.com/RamCart/CartPutItem.php' method='POST'>
<input type='checkbox' name='part[]' value='RAM-VB-162'>
<input type='checkbox' name='part[]' value='RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>

Re: implode function not working

Posted: Fri Oct 03, 2008 10:09 am
by Kadanis
I'm not sure what the rest of your processing script does so can't really help, but when i tested this snippet on our dev server it worked fine and returned the following from a var dump

Code: Select all

 
array(1) { 
    ["part"]=>  array(2) { 
        [0]=>  string(10) "RAM-VB-162" 
        [1]=>  string(10) "RAM-VB-154" 
    } 
} 
 
RAM-VB-162^RAM-VB-154 
 
This is the snippet I tested, called test.php

Code: Select all

 
<?php
var_dump($_POST);
 
if(isset($_POST['part'])) {
$checkbox = $_POST['part'];
$string = implode("^",$checkbox);
echo $string;
}
?>

Code: Select all

 
<form name='CartItem' action='test.php' method='POST'>
<input type='checkbox' name='part[]' value='RAM-VB-162'>
<input type='checkbox' name='part[]' value='RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>
 

Re: implode function not working

Posted: Fri Oct 03, 2008 10:31 am
by tonyledenko
When I submit the following it works. Just wondering why its not working with PHP. Thanks anyway.

<form name='CartItem' action='https://www.ram-mount.com/RamCart/CartPutItem.php' method='POST'>
<input type='hidden' name='part' value='RAM-VB-162^RAM-VB-154'>
<input type='submit' value='Add To Cart'>
</form>

Re: implode function not working

Posted: Fri Oct 03, 2008 10:37 am
by Kadanis
Sounds like there could be something else going on, as the suggested code should work in a normal HTTP / PHP environment. Weird.

Good Luck anyway.