PDA

View Full Version : 2 form actions, 2 submit button, 1 input text field



mtran
10-23-2007, 06:35 PM
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.

boogyman
10-23-2007, 06:47 PM
make them all submit buttons but assign different values depending on what you need done... eg



<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


if( isset($_POST['srch_word'] )
{
something();
}
else if( isset($_POST['srch_part']) )
{
something_else();
}

djr33
10-23-2007, 06:50 PM
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.

mtran
10-23-2007, 07:32 PM
Thank you!

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

boogyman
10-23-2007, 07:38 PM
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.

mtran
10-23-2007, 07:49 PM
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...

boogyman
10-23-2007, 07:56 PM
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.

djr33
10-23-2007, 09:27 PM
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.

mtran
10-24-2007, 06:11 PM
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.

Twey
10-24-2007, 06:33 PM
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.

djr33
10-24-2007, 07:04 PM
Debatable. I'd say the best solution woudl be having two then rewriting to one with JS, and leaving it as that, but I see that as quite difficult.
Also, it would still work, but only for a single button, if javascript was disabled; the other wouldn't override the action.


Likely very invalid, but what would happen if you have one form within another. The second submit button could be on the outer form, then submit the inner fields as well (maybe), and the inner field would just act alone. Or not...

Twey
10-24-2007, 11:35 PM
Debatable.No. Not at all. Accessibility comes before presentation, always.
I'd say the best solution woudl be having two then rewriting to one with JS, and leaving it as that, but I see that as quite difficult.That would indeed be the best solution.
Also, it would still work, but only for a single button, if javascript was disabled; the other wouldn't override the action.Depending on how it's set up. It could work like this. Still inferior to having two separate forms either way, though.
Likely very invalid, but what would happen if you have one form within another. The second submit button could be on the outer form, then submit the inner fields as well (maybe), and the inner field would just act alone.Very invalid indeed, thus there's no way of telling what would happen. I wouldn't expect it to work in current browsers, though.