FORUMS: list search recent posts

PHP Text input as checkbox

COW Forums : Web Design

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Richard Williams
PHP Text input as checkbox
on Jan 3, 2011 at 11:31:14 pm

I have a dynamic list on my website, and have checkboxes next to content, calling the content when a box is checked. THis all works very well thank you very much...

Trouble is, the client wants to have an input field, not a checkbox. They want the list to appear, and if someone puts a quantity in the box, THEN the value of the input box, as well as the list value is sent across...

Has anyone done this before? I am contemplating trying to change his mind and putting a quantity box on the recieving page instead... but i would like to attempt what he is asking for first. (not that i havent been playing myself)

Thanks

Richard

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index

Fernando Mol
Re: PHP Text input as checkbox
on Jan 4, 2011 at 3:51:45 am

It will be a list of items with a text field for quantity?

huevos ( 1 )
jamón ( 5 )
tocino ( 3 )


If that's the case, then you can simply send the number, then in the results page you can do the math to display the final value (price * quantity).

Did I get it right?


Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 11:17:03 am

No Fernando. What i have is a long list of products on the page, and at the moment you tick the box of the items you want, then press send, and you recieve a new list of only the items that were ticked.

What i want to happen is i want to put a quantity box next to the items, INSTEAD of the tick box. Then whatever item you put > 0 in the box next to, creates the new list.

Does this make sence?

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index


Abraham Chaffin
Re: PHP Text input as checkbox
on Jan 4, 2011 at 3:49:02 pm

Hello Richard,

Do you have a URL example?

I'm hearing what I think Fernando is hearing you say. The input quantity fields are going to have a name with a product id or some other key that will tell your system what product the quantity value is to be paired with:

<ul>
<li>
Product 1: <input type='text' size=2 value='' name='product_qnty_1' />
</li><li>
Product 2: <input type='text' size=2 value='' name='product_qnty_2' />
</li><li>
Product 3: <input type='text' size=2 value='' name='product_qnty_3' />
</li>
</ul>



If your form method is post you might try doing a

echo var_dump($_POST);

To check what variables are being passed before you move forward.

Abraham


Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 5:17:13 pm

ok here is an example.


So my check box WAS <input name="chkBox" type="checkbox" id="chkBox" value="<?php echo $row_Recordset1['description']; ?>" />


I repeated the region, and it listed all my items in my recordset no problem.


When i tick the boxes however, and send to my form, i origionally called a new recordset, and matched the recordset to filter by form variable chkBox = to description. Again, this worked but only with one box ticked. It did not pull in more info if i had two or more boxes ticked.


So... with my google powers, i googled what i was trying to do and it told me to make the checkbox name include square brackets... []


As you can see in this exapmple now, i have renamed chkBox as item[]


<input name="item[]" type="checkbox" id="chkBox" value="<?php echo $row_Recordset1['description']; ?>" />


OK, so in my recieving page, i have this code...


<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
foreach ($item as $itemS)


{
echo "You ordered ". $quantity . " " . $itemS . ".<br />";
}


echo "Thank you for ordering from Tizag Art Supplies!";


?>


Now it echos all the items i tick. GREAT.


So i thought ok, lets do the same with the quantity. But of course it doesnt work like that does it. So how do i make the quanitity box relative to the records, and echo on my other page??? It just doesnt work. I tried this


<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
foreach ($item as $itemS)
foreach ($quantity as $quantityS)
{
echo "You ordered ". $quantityS . " " . $itemS . ".<br />";
}


echo "Thank you for ordering from Tizag Art Supplies!";


?>


But all that does is repeat the recordset 10times and puts the value in the column that it was typed in.


THe OVERALL goal was to not have a tick box at all, just a value box, where you entered a number and it then took that as selected bringing it across to the processor.php, but i cant even figure out how to bring a number across even WITH the tick box so i have no hope.


Not being very bright with PHP without dreamweaver guiding me... i tried a "while" statement...


<?php
$quantity = $_POST['quantity'];
$item = $_POST['item'];
foreach ($item as $itemS)
foreach ($quantity as $quantityS)
while ($quantityS > 1)
{
echo "You ordered ". $quantityS . " " . $itemS . ".<br />";
}


echo "Thank you for ordering from Tizag Art Supplies!";


?>


This seems to do what i want it to do.... just it pulled it in to processor.php an infinate number of times over and over and over.................




Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)



Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 5:26:02 pm

to clarify... the actual page acording to how the client would like would be recordset list... and an input box. When you a number in the input box, this "activates" that record ready to be moved on to processor. Im pretty sure i could do an on change and use hidden fields with this maybe... but who knows im a bit mind numb after having achieved NOTHING all day on this and going around in circles. The whole site is complete bar this flipping trasaction which i left till last thinking it would take me a few minutes... TWO days ago.. :-S

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index



Abraham Chaffin
Re: PHP Text input as checkbox
on Jan 4, 2011 at 5:43:41 pm

Hello Richard,

Try something like this on the sending page for the quantity input field:


<?=$row_Recordset1['description']?>: <input type='text' size=2 value='' name="product_qnty_<?=$row_Recordset1['description']?>" />


This will put the key of the post field as product_qnty_ with the product description that you're using to find the product (though this would be better if it was a product id). The post value will be a numeric quantity.


On the processing page you can get your product quantity information by doing something like this:


<?
//KEY FOR QUANTITY FIELDS
$qnty_key="product_qnty_";

//LOOP THROUGH THE POST FIELD
foreach($_POST as $key => $val)
{
//IF THE BEGINNING OF THE POST FIELD IS THE QUANTITY KEY AND THE VALUE IS A NUMBER AND THE NUMBER IS OVER ZERO
if(substr($key,0,strlen($qnty_key))==$qnty_key && is_numeric($val) && $val > 0)
{
$prod_description=substr($key,strlen($qnty_key));
echo $prod_description.": ".$val."<br/>";
}
}
?>



I didn't check the code but it should work.

Abraham


Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 5:56:23 pm

OMG... Thanks dude...

i hate that im so thick... Can't you delete this post for now and re-post it in a few days with something like "ok richard, ive been working on this for days now and think i finally got the solution..."

lol

Thanks alot Abraham I REALLY appreicate it!

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 6:01:38 pm

oh... one last Q..

Can i display it without filling the spaces in with _ ?

Thanks

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index


Abraham Chaffin
Re: PHP Text input as checkbox
on Jan 4, 2011 at 6:05:09 pm

I assume you are referring to the quantity key that I set which has the underscores.

$qnty_key="product_qnty_";

The product key can be just about anything you want just so it's the same for your form and when you are processing.

Abraham


Return to posts index

Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 6:11:55 pm

oh no sorry... the echo of the values displays the recordset but puts all the whitespaces as _

look here after you submit a value it brings the recordset values up but with _ showing

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index


Abraham Chaffin
Re: PHP Text input as checkbox
on Jan 4, 2011 at 6:20:37 pm

Well - I guess that's one reason why it's better to pass an id with your key rather than a text description.

Do you have a numeric product id you could pass and then tie it back to the description on the other side of the posting?

If not you could do something like this:

<?
//SET YOUR ID TO ZERO BEFORE THE LOOP
//USE THE ID TO MATCH PRODUCT INFORMATION AFTER POSTING
$id++;
?>
<?=$row_Recordset1['description']?>: <input type='text' size=2 value='' name="product_qnty_<?=$id?>" />
<input type='hidden' name='product_desc_<?=$id?>' value="<?=$row_Recordset1['description']?>" />



This isn't really the best way at going at this but since I don't know your entire setup it helps fix what you're trying to do.


Altered processing:

<?
//KEY FOR QUANTITY FIELDS
$qnty_key="product_qnty_";

//LOOP THROUGH THE POST FIELD
foreach($_POST as $key => $val)
{
//IF THE BEGINNING OF THE POST FIELD IS THE QUANTITY KEY AND THE VALUE IS A NUMBER AND THE NUMBER IS OVER ZERO
if(substr($key,0,strlen($qnty_key))==$qnty_key && is_numeric($val) && $val > 0)
{
$id=substr($key,strlen($qnty_key));
$prod_description=$_POST['product_desc_'.$id];
echo $prod_description.": ".$val."";
}
}
?>

Abraham


Return to posts index


Richard Williams
Re: PHP Text input as checkbox
on Jan 4, 2011 at 7:16:14 pm

thanks man

Richard Williams
p.s. Please remember to rate our post replies and tick if solved. Also, please remember that we here are NOT employed by Adobe, we do this out of love and fun, so its always nice to recieve a Please and Thank You! :o)


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]