Page 1 of 1

Newbie question about forms and submitting

Posted: Fri Mar 21, 2008 9:04 pm
by opet
Hello peeps,

My first post in this forum is going to be a relatively simple one I believe.

I got a piece of code similar to this:

Code: Select all

<form title="xxx" action="do.php" method="GET" name="xxx" id="xxx" selected="true">
        <fieldset>     
            <div class="row">
                <label><?php echo( $cmd ); ?></label>
                <a class="button" href="do.php?id=<?php echo($id);?>">Toggle</a>
           </div>
           <?php $id++; } ?>
         </fieldset>
         
         <fieldset>
            <div class="row">
                <select name="id class="date">
                    <option value="0">Select source
                    <option value="1">xxx
                    <option value="2">xxx
                    <option value="3">xxx
                    <option value="4">xxx
                    <option value="5">xxx
                    <option value="6">xxx
                <select>
            </div>
        </fieldset>
                <a type="submit" href="#">Select source</a>
 
    </form>
My problem is as follows. I haven't touched HTML +++ for years, and I really can't figure out how to generate the correct form url here. What i want is to end up with "do.php?id=0", "do.php?id=1" etc. by selecting from the list, and then clicking the button. But I can't seem to even get a do.php url... And is it possible to only submit the form, and not reloading or linking to new page?

I really hope someone can just explain this really quick.

Thanks in advance,

Øyvind

Re: Newbie question about forms and submitting

Posted: Fri Mar 21, 2008 11:13 pm
by JAB Creations
When you see a file request such as file?query=value that is a GET request, not a POST request.

Also your page will not validate as you're missing the end quote on one of your name attributes.

Re: Newbie question about forms and submitting

Posted: Sat Mar 22, 2008 8:44 pm
by califdon
You seem to be trying to write a link or anchor tag as your button. Why aren't you just using the standard Submit button? Do correct your closing </select> tag. And as someone else pointed out, do correct the missing " at the end of the name of your select element.

I haven't learned XML, so I'm unable to show corrected code, but in plain HTML, it would look like this:

Code: Select all

<form title="xxx" action="do.php" method="GET" name="xxx" id="xxx">
   <div class="row">
       <select name="id class="date">
          <option value="0" selected>Select source
          <option value="1">xxx
          <option value="2">xxx
          <option value="3">xxx
          <option value="4">xxx
          <option value="5">xxx
          <option value="6">xxx
       </select>
       <input type="submit" value="Submit">
  </div>
</form>
Is there some reason that you prefer to use the GET method over the POST method? Generally, this kind of form submission would probably be done using POST.