I need help with javascript/php!

Hi guys, I'm trying to figure out how to parse results from one form into another form. I never learned php or javascript while in school, so I'm trying to learn it now.

Specifically, what I am trying to do right now is display a list of checkboxes via html5 for the user to select, and then based on what the user selects, have that fill into another form via a string. I don't know if I should do this using php or if I could do it just using javascript. I'm not really trying to upload to a database as far as I know, but that is something that I should learn as well.

So for checkbox:

Apple = checked
Orange
Mango = checked

New Form
Fruit Selected:
Apple
Mango

My html code:

Code:

Please help lol

Fruit Picking

Directions: Select each of the types of fruit you want!

Fruit

Please select up to three
Apple
Orange
Mango

Thank You for using this form!

Here is a picture of what it looks like:

Again, I want the value of what is actually checked to display in a new page/form.

You mentioned PHP, so I’m assuming you’re on a server running PHP and your dev environment is ready to go!

Basically, web apps send data between pages by the URL/Querystring which you’ll see as some_page.php?key=value (which can be done using the form method GET, or manually constructing the query string, etc.), or by a POST (like your current FORM).

Then the “receiving” page just needs to access those values. In PHP, this is done through the $_GET[] and $_POST[] variables.

If you POST your form, you’ll need to indicate the page that will handle the POST processing, so let’s say the page you posted is form_main.php (or .htm since it doesn’t actually contain any server script). You’ll just want to change the FORM section to something like this:

Note that I really didn’t deal with the VALUE as I just wanted to know if it was set, the checkbox itself provides the value logic so to speak.

The construct above is a typical bit of control logic:

if(check for something)
{
logic if it checks/exists

}
else
{
logic if it doesn't

}

Now, you’ve got an extra level of complexity because your checkboxes have the same NAME, that means, the code will not know which one to access, so they’ll be handled in an array, where you’ll need to recurse through, determine if it’s set, then get the value, and you’ll want to use the [] to denote the name will be handled as an array.

In fact, I’d say maybe rename your inputs to different names to get a handle on all the above and we can revisit, or I can toss up some code that will take the array group1 and recurse it, just didn’t want to overload you

[edit]

OK, I’ll toss up handling a checkbox array since I’m already there

put the [] suffix on each element name, so group1[], and give each element a name that conveys the logic (the name of the fruit would be perfect):

What this does is create an array of all the items selected in the same group1[], arrays are lists of data, and each element can be selected by using an indexer, which is a integer value that indicates the position in the array starting from 0

The count() function returns the number of items (you’d have a max of 3), then the for loop gets each one by substituting a number starting from 0 to the number of items total in the array, so $fruit[0], $fruit[1]

The . notation is to concatenate strings, and you can see I’ve put a string value of