Help with checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exkenzo
Forum Newbie
Posts: 4
Joined: Wed Jan 26, 2011 10:34 am

Help with checkbox

Post by exkenzo »

Hello :)
This is the code for a checkbox, the results shall be within a form, but what I want to know is how do I get the address of the checkbox results in a description?

Code: Select all

<html>
    <head>
        <title>Color</title>
    </head>
    <body>
        <h1>LIST CHECKBOX</h1>
        <p>
            <form method="post" action="recuveraCheckbox.php">
                <input type="checkbox" name="myCheck[a]" value="Green" /> Valore A
                <br />
                <input type="checkbox" name="myCheck[b]" value="Red" /> Valore B
                <br />
                <input type="checkbox" name="myCheck[c]" value="Black" /> Valore C
                <br />
				
                <input type="submit" value="submit form" />
            </form>
        </p>
		
    </body>
</html>  

I would also create a button to increase the checkbox available, so having a button that gives me the ability to create value.
I do not know much php, I am learning, and I need a hand to write this code.
I thank those who can give me some help.
:)
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Help with checkbox

Post by danwguy »

if you are asking how to get whatever checkbox they checked in your recuveraCheckbox.php file just use a variable like this...

Code: Select all

$checkbox = $_POST['checkbox'];
echo $checkbox;
Though you need to change your form so that they all have the same name, just keep the values different and that above will grab whatever they checked and echo it back to the page. I am not sure what you mean with
I would also create a button to increase the checkbox available, so having a button that gives me the ability to create value.
If you mean you want them to be able to add their own input use <input type="text" name="value" maxlength="50" /> on your form and then in the php file use the same method...

Code: Select all

$value = $_POST['value'];
echo $value;
If that's not what you are looking for I'm sorry, please be a little more clear and I will do my best to help you out.
exkenzo
Forum Newbie
Posts: 4
Joined: Wed Jan 26, 2011 10:34 am

Re: Help with checkbox

Post by exkenzo »

I am writing the code that I have to change is code Virtuemart (Joomla module), is within the "Aggiungi Prodotto" I do not know if you have had occasion to use it.
Here, I would add a checkbox just after the section of "Categorie"of products. Every choice I make in my checkbox is added in the form of "Descrizione per Negozio", where I would also add a header for description.
As regards the checkbox button, I create it so that gives me the opportunity to add a new choice of its value in the checkbox, of course I must give the possibility to write the new value.

I enclose the image of the "new product".
Attachments
product2.png
product2.png (41.63 KiB) Viewed 114 times
Last edited by exkenzo on Thu Jan 27, 2011 4:55 am, edited 1 time in total.
exkenzo
Forum Newbie
Posts: 4
Joined: Wed Jan 26, 2011 10:34 am

Re: Help with checkbox

Post by exkenzo »

product_form attach the file, that code should I change
Attachments
product_form.rar
(12.84 KiB) Downloaded 7 times
exkenzo
Forum Newbie
Posts: 4
Joined: Wed Jan 26, 2011 10:34 am

Re: Help with checkbox

Post by exkenzo »

an idea, I can insert html code in php code, right?
and if so, how do I enter it correctly?
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: Help with checkbox

Post by danwguy »

You can insert any html you want in php. either end the php with ?> or use the echo command to put in on the page like this...

Code: Select all

<?php
echo "<form action='send.php' method='post' name='form' />Yes";
echo "<input type='radio' name='choice' value='yes' id='yes' />No";
echo "<input type='radio' name='choice' value='no' id='no' />";
echo "<input type='submit' value='press to choose' />";
?>
Then in send.php you can find out which one they pressed with...

Code: Select all

<?php
$yes = $_POST['choice'];
if($yes == 'yes') {
echo "You chose yes!!";
}
if($yes == 'no') {
echo "You chose no!!";
}
?>
Sorry I am not sure what to do on that program you posted or the screenshot, I don't know what language that is. The way I just posted is the way I have always done it. Feel free to test it out so you can see how that works.
Post Reply