Link to home
Start Free TrialLog in
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']}
.
.
.
ASKER CERTIFIED SOLUTION
Avatar of Radek Baranowski
Radek Baranowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geeta_m9
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']}
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.
I am not sure. But since both the name and id are identical in this case, I guess it doesn't matter.
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.
The form I am using is an external form used in Concrete 5.
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>
Thanks.