6 Replies Latest reply on Feb 12, 2015 8:10 AM by r_tist

    input and select...

    r_tist Level 1

      Hi,

       

      Wanted to alter source code so that it would be a dropdown pick list instead of a txt field. Where I'm unsure... does 'select name' replace 'input' in this case? Or does 'input' still need to be there even though not a field as such? Also, if it does need 'input-type="?what word attribute for pick list?"'

       

      With my alterations:

      <div class="formblock">

                                <label class="screen-reader-text">How did you hear about this?</label>

                                 

                                   <select name="howHeard" id="howHeard" value="<?php if(isset($_POST['howHeard']))  echo $_POST['howHeard'];?>" class="tick">

                                    <option value="volvo">Volvo</option>

                                    <option value="saab">Saab</option>

                                    <option value="mercedes">Mercedes</option>

                                    <option value="audi">Audi</option>

                                  </select>

                                 

                                  <?php if($howHeardError != '') { ?>

                                      <br /><span class="error"><?php echo $howHeardError;?></span>

                                  <?php } ?>

                              </div>

       

      Other field example that I sourced, which is set up correctly:

       

      <div class="formblock">

                                  <label class="screen-reader-text">Email</label>

                                  <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="txt requiredField email" placeholder="Email:" />

                                  <?php if($emailError != '') { ?>

                                      <br /><span class="error"><?php echo $emailError;?></span>

                                  <?php } ?>

                              </div>

       

      Thanks.

        • 1. Re: input and select...
          osgood_ Level 8

          r_tist wrote:

           

          Hi,

           

          Wanted to alter source code so that it would be a dropdown pick list instead of a txt field. Where I'm unsure... does 'select name' replace 'input' in this case? Or does 'input' still need to be there even though not a field as such? Also, if it does need 'input-type="?what word attribute for pick list?"'

           

          With my alterations:

          <div class="formblock">

                                    <label class="screen-reader-text">How did you hear about this?</label>

                                    

                                       <select name="howHeard" id="howHeard" value="<?php if(isset($_POST['howHeard']))  echo $_POST['howHeard'];?>" class="tick">

                                        <option value="volvo">Volvo</option>

                                        <option value="saab">Saab</option>

                                        <option value="mercedes">Mercedes</option>

                                        <option value="audi">Audi</option>

                                      </select>

                                    

                                      <?php if($howHeardError != '') { ?>

                                          <br /><span class="error"><?php echo $howHeardError;?></span>

                                      <?php } ?>

                                  </div>

           

          Other field example that I sourced, which is set up correctly:

           

          <div class="formblock">

                                      <label class="screen-reader-text">Email</label>

                                      <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="txt requiredField email" placeholder="Email:" />

                                      <?php if($emailError != '') { ?>

                                          <br /><span class="error"><?php echo $emailError;?></span>

                                      <?php } ?>

                                  </div>

           

          Thanks.

           

           

          Your code below is correct, no input field required.

           

          <div class="formblock">

          <label class="screen-reader-text">How did you hear about this?</label>

          <select name="howHeard" id="howHeard" value="<?php if(isset($_POST['howHeard']))  echo $_POST['howHeard'];?>" class="tick">

          <option value="volvo">Volvo</option>

          <option value="saab">Saab</option>

          <option value="mercedes">Mercedes</option>

          <option value="audi">Audi</option>

          </select>

          <?php if($howHeardError != '') { ?>

          <br /><span class="error"><?php echo $howHeardError;?></span>

          <?php } ?>

          </div>

           

          Values are retrieved like

           

          $value = $_POST['howHeard'];

           

          What ever option is select at the time will get attributed to the $value variable

          • 2. Re: input and select...
            BenPleysier Adobe Community Professional & MVP

            The value that for the select is the chosen option value, as opposed to an input type text (or similar) where the value is placed inside the box.

             

            As a side note, the label element should have a for-property, referring to the input element.

            • 3. Re: input and select...
              r_tist Level 1

              OK, it's as what I suspected then! - phew! Can't wait to test it later...

               

              Can you ellaborate on: "As a side note, the label element should have a for-property, referring to the input element."

              Please explain so I can understand.

               

              Thanks!

              • 4. Re: input and select...
                osgood_ Level 8

                r_tist wrote:

                 

                OK, it's as what I suspected then! - phew! Can't wait to test it later...

                 

                Can you ellaborate on: "As a side note, the label element should have a for-property, referring to the input element."

                Please explain so I can understand.

                 

                Thanks!

                 

                 

                 

                <label for="howHeard" class="screen-reader-text">How did you hear about this?</label>

                • 6. Re: input and select...
                  r_tist Level 1

                  ok, I added that. as it is powered by php, my page is an .html single page site. my intention is to insert this form into the footer.

                  any recommendations how I can do that? can I copy the form code and insert? do I simply change extension of file to php?

                  (un-chartered territory for me here!)

                   

                  Alternatively, if you know how I can change the code above to make HTML only - that would be fine if easier. I just would like it to function...

                   

                  Thank you!