Avatar of geeta_m9
geeta_m9
 asked on

How do I include a drop down list box in a PHP form?

I am updating a PHP form which has some form elements like radio buttons, check boxes and text boxes. I would like to include a drop down list box in the form which has the options 1 through 13 for the user to select but am not sure of the correct syntax.

For example, some of the code in the form is as follows:
.
.
.
<div class="field field-email">
                    <label for="emailAddress">E-Mail<span class="required">*</span></label>
                    <input name="emailAddress" id="emailAddress" type="email" value="" />          
                </div>

 <div class="field field-textarea">
                    <label for="howHear">How did you get to know about Apicius?</label>
                    <textarea name="howHear" id="howHear" cols="50" rows="3" style="width:95%"></textarea>            
                </div>
               
                <div class="field field-radios">
                    <label >Knowledge of the Italian Language?</label>
                    <div class="radioList">
                        <input name="italianLevel" type="radio" value="Beginner"  />&nbsp;Beginner
                        <input name="italianLevel" type="radio" value="Intermediate"  />&nbsp;Intermediate
                        <input name="italianLevel" type="radio" value="Advanced"  />&nbsp;Advanced
                </div>
.
.
.

There is also a separate "controller form" which submits the form entries as email parameters, e.g. the above entries would be represented as follows:
.
.
.

E-Mail: {$params['emailAddress']}

How did you hear about Apicius?  {$params['howHear']}

Knowledge of the Italian Language? {$params['italianLevel']}
.
.
.
PHPJavaScriptHTML

Avatar of undefined
Last Comment
geeta_m9

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Radek Baranowski

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
elepil

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
geeta_m9

ASKER
What about the "id" part. Don't I need that too?

Also when I pass the input as a parameter in the controller form, do I just write:

FormFieldName: {$params['formFieldName']}
elepil

Whether you use "id" or "name" depends on how you're processing your form. From your code, I'm seeing both, and I'm not sure why. In your code snippet, you indicated you were obtaining your form values by:

E-Mail: {$params['emailAddress']}

Open in new window


Since "id" and "name" both have identical values, I'm not sure which one you're picking up the 'emailAddress' value from.

Are you using some kind of PHP framework? Because I process my forms pretty much like Radek Baranowski does (the other responder). So I'm not sure how you got your form values into an array called $params.
geeta_m9

ASKER
I am not sure. But since both the name and id are identical in this case, I guess it doesn't matter.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
elepil

Geeta,

It sounds like you are using a framework, and I say that because you used the word "controller form". That word is never used when you're simply processing a HTML form using PHP scripts on the server side. So maybe your question pertains to the framework that you are using? It sounded like you were originally just asking about the syntax for a HTML dropdown, but it sounds like your question spans way beyond that.
geeta_m9

ASKER
The form I am using is an external form used in Concrete 5.
Vimal DM

Hi,

<form action="dump.php" method="POST" name="form">
<select name="selmenu" onChange="findselected()">
  <option value="1">Choice 1</option>
  <option value="<?php echo $wah;?>">Choice 2</option>
</select>
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
geeta_m9

ASKER
Thanks.