Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: 2 form actions, 2 submit button, 1 input text field

  1. #1
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 2 form actions, 2 submit button, 1 input text field

    hi, is it possible to have 2 forms actions, 2 submit buttons, but only 1 input text field sharing between the 2 forms?

    I'm working on a web search and the company requires to have ONE search box [input text field] and 2 submit buttons "Search by Part" and "Search by Keyword" side by side.

    Clicking "Search by Part" will append ABC parameters and take you to SearchbyPartResultPage, and clicking "Search by Keyword" will append XYZ parameters and take you to SearchbyKeywordResultPage.

    Is it doable? Thanks for the inputs.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    make them all submit buttons but assign different values depending on what you need done... eg

    Code:
    <input type="submit" name="srch_word" value="Search By Keyword">
    <input type="submit" name="srch_part" value="Search By Part">
    then where ever you are processing the information you determine which was selected and process from there
    PHP Code:
    if( isset($_POST['srch_word'] )
    {
         
    something();
    }
    else if( isset(
    $_POST['srch_part']) )
    {
         
    something_else();


  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Boogyman's solution is probably the best, though it would be possible to actually submit to two different pages based on which button was clicked, using javascript, I think. Will the PHP work? I think it would/should in this case.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you!

    What if a solution using only javascript. I'm in Websphere, all I can use is html and javascript

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    What if a solution using only javascript. I'm in Websphere, all I can use is html and javascript
    how is the information being stored? if you are trying to search for something that is implying that you are using some type of database / back-end support.

  6. #6
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    That's still a ...mystery for me.
    In that Content Management Sys - I only have the ability to import "search portlet" on the search result page - pre-configured porlet.

    As for the search box, it's in a sort of html portlet, all parameters have been set up via <input hidden....> in individual forms.

    I suggested a workable solutions: just using radio buttons asking users to select which search they want to use and hide/show the relevant search box and submit button. But they prefer 1 search box and 2 buttons and I'm working on it, not sure how...

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    well if you have no access to the back end processing then having 2 buttons will do nothing. I would inquire as to how the data is being processed, and after you figure that out you would be able decide what to do with the front-end processing.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, if you do have no access but different URLs would allow for different options, I'd suggest javascript.

    However, I'm not quite sure what the best way to do this would be.

    Some ideas--

    Have a value of the button; dynamically change the action of the form based on that value, then submit. Alternatively, onSubmit, get the value of the last clicked button and then apply that to the action. I'm not sure which works best.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I've luckily made it work. Thanks for the inputs!
    I dynamically change the form action and all of the related parameters based on which button is clicked.
    So even though it's like having 2 forms, html-wise it's only one form with 2 submit buttons.

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is not an acceptable solution. Users without Javascript will not be able to use your form. You'd be better off having two forms than doing this.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •