views:

72

answers:

3

first: always is the same action. two: the form has multiple "CSS SUBMITS" like

<form action="/myaction" method="POST">
<a id="foo1" name="foo1" href="#" role="form_button">submit1!</a>
<a id="foo2" name="foo2" href="#" role="form_button">submit2!</a>
<a id="foo3" name="foo3" href="#" role="form_button">submit3!</a>
<input type="submit" id="canfoo" name="canfoo" value="I can process this"/>
</form>
<script>
$('a[role=form_button], div[role=form_button], span[role=form_button]').bind( 'click', function(){ $('form').submit(); } );
</script>

how can I do in /myaction this:

if ($_POST['foo1']) { action; return; } // :(
if ($_POST['foo2']) { action; return; } // :(
if ($_POST['foo3']) { action; return; } // :(
if ($_POST['canfoo']) { action; return; } // THIS WORKKKKKSS!!

How can I do to foo1, foo2, foo3 to work?

(I use jQuery like:

$('a[role=form_button], div[role=form_button], span[role=form_button]').bind( 'click', function(){ $('#actiontodo').val(this.id); $('form').submit(); } );

), then, in the other side (action),

I do:

IF ($_POST['ACTIONTODO'] == "foo") { action; return; }

BUT, I DON'T LIKE THIS SOLUTION! I WANT THE <A behave as well as <input type="submit"

Thank you very much for your help!

+6  A: 

You shouldn't give priority to visual over usability, that's a huge mistake. Anyway, you can stylize any button/input to suit your needs without any problem, just grab a good CSS tutorial.

Don't reinvent the wheel.

Ben
Amen and +1 for not distorting your HTML semantics in the (mistaken!) name of "looks" -- I just wish every web user with visual problems could join me in upvoting this!
Alex Martelli
I know the input's can stylized ... only I want to know if is possible to send the same information to the action as well as input's using other HTML structures (tags)
Cris Hong Kong CRISHK
@Ben - you get my upvote ;)
slomojo
@user439866 You can but you need to use Javascript in order to (check slomojo's answer), rendering your form useless for those with JS disabled. And trust me, anything you can do to stylize an anchor tag, a span or a div you can do it to an input/button (including background images)
Ben
look the GMAIL email buttons at the top of the messages, that buttons aren't inputs!!!!! I know these buttons use AJAX, but I want to create the same buttons using a natural POST!
Cris Hong Kong CRISHK
first understand the really question, then answer ... I know my english is not the best, but if you look the examples, you can't solve this question easy ... Try to do a "natural SUBMIT" to POST action, without use inputs, only javascript or jquery (no AJAX) ... then come here and answerr!! BEEEEEN babyyyyy!!!
Cris Hong Kong CRISHK
I'm not reinventing the wheel.. You can't like the easy solutions to all... you need to find other ways...
Cris Hong Kong CRISHK
@user439866 Alright, first of all, if you disable JS (download the Firefox noScript complement) Gmail uses inputs. Second, why on earth, if you're not using AJAX, you want to simulate a button when you can use a a button!, I already told you, you can apply whatever style you need to a button as much as you could to an anchor (a) or a div. Fourth, Google is not the "rule book of coding".
Ben
Hi, finally I solved it using a <button type="submit" ... this is the answer yo my question! thanks to all! bye!:). The difference with <input type="submit" is: I can put content inside the button ...
Cris Hong Kong CRISHK
+1  A: 

You can use any element you want to trigger a .submit() event.

For example, this form:

<form id="targetForm" action="/myaction">
   <input type="text" value="Oh hai!"/>
</form>

Can be submitted by the following jQuery:

$('#targetForm').submit();

However, you can style buttons and input fields without too much trouble in CSS.

Update:

I'd agree with Ben that you should reconsider doing form submissions this way.

For multiple submission triggers..

So if you have multiple triggers you need a hidden field to record this information for POST.

Something like this will do the trick...

<form id="targetForm" action="/myaction">
   <input type="text" name="myText" value="Oh hai!"/>
   <input type="hidden" name="whichTrigger" value="default" />
</form>

And then each trigger would do ...

$('#whichTrigger').val("myTriggerName"); // A different value for each one of course.
$('#targetForm').submit();
slomojo
first: always is the same action.two: the form has multiple "CSS SUBMITS" like <a id="foo1" name="foo1" href="#" role="button">submit1!</a><a id="foo2" name="foo2" href="#" role="button">submit2!</a><a id="foo3" name="foo3" href="#" role="button">submit3!</a><script>$('a[role=form_button], div[role=form_button], span[role=form_button]').bind( 'click', function(){ $('form').submit(); } );</script>how can I do in /myaction this:if ($_POST['foo1']) { action; return; } if ($_POST['foo2']) { action; return; } if ($_POST['foo3']) { action; return; }
Cris Hong Kong CRISHK
Code is insanely hard to follow in comments unless it's a single line. Please update you question. Thanks.
slomojo
However, at a guess I think you'd just need to set a hidden field to indicate which form submission trigger was used.
slomojo
updated! read the last part!
Cris Hong Kong CRISHK
Yep, see my comment above, it covers this, I'll update my answer to show an example.
slomojo
A: 

I solved this problem as is:

<form action="/myaction" method="POST">
<div id="foo1" name="foo1" href="#" role="form_button"><button type="submit">submit1!</button></div>
<div id="foo2" name="foo2" href="#" role="form_button"><button type="submit">submit2!</button></div>
<div id="foo3" name="foo3" href="#" role="form_button"><button type="submit">submit3!</button></div>
<input type="submit" id="canfoo" name="canfoo" value="I can process this"/>
</form>

!!!!!!!!!!!!!!!!!!! THANKS!

Cris Hong Kong CRISHK
-1 `<button type="submit">submit1!</button>` === `<input type="submit" value="submit1!">`
Ben
IIIIIIIIIIIIII KNOWWWWWWWWWW BEN! ... KISS PAPI!
Cris Hong Kong CRISHK