Skip navigation
Currently Being Moderated

creating a button

May 25, 2012 5:51 AM

Is there any way to convert this to a submit button?  here is my code:

<a class="button small red" href="#" id="submitUpload"><span>Submit</span></a>

 

I followed this tutorial: http://acrisdesign.com/2011/06/create-a-multi-color-and-size-css3-butt ons/#

 
Replies
  • Currently Being Moderated
    May 25, 2012 11:10 AM   in reply to future-architect

    <a class="button small red" href="#" id="submitUpload" onclick="document.forms['formName'].submit();"><span>Submit</span></a >

     
    |
    Mark as:
  • Currently Being Moderated
    May 26, 2012 9:13 AM   in reply to future-architect

    Yes, that would only work with javascript enabled.  If you want to cover both eventualities, you could put a normal submit button inside a pair of <noscript> tags - then you'd have to figure out how to hide the other button when there is no javascript enabled.

     
    |
    Mark as:
  • Currently Being Moderated
    May 26, 2012 12:20 PM   in reply to future-architect

    Is 'fileUpload' the name of your 'file' field?  You would have to test for that this way -

     

    if($_FILES['fileUpload']) {

     
    |
    Mark as:
  • Currently Being Moderated
    May 27, 2012 5:15 AM   in reply to future-architect

    Sorry for my previous goofy answer.  The data was staring me in the face and I missed it!

     

    Try making your code look like this -

     

    onclick="document.forms['fileUpload'].submit();"

     

    You need the name of the form being submitted in that location, not the name of a field.

     
    |
    Mark as:
  • Currently Being Moderated
    May 27, 2012 8:02 AM   in reply to future-architect

    Now you've confused me.  The PHP would have to be conditional on some element that is present in the $_POST array.  The form name is not. So, if(isset($_POST['form_field_name']) && $_POST['form_field_name'] == 'some_value') { ?>

     

    The javascript would submit based on the form's name attribute value, i.e., document.forms['fileUpload'].submit();

     
    |
    Mark as:
  • Currently Being Moderated
    May 27, 2012 8:40 AM   in reply to future-architect

    I would use this -

     

    <?php if (array_key_exists('some_field_name', $_POST) {

    //processing code follows

    ...

    }

    ?>

     

    So far, we don't know the name of any of your form's fields - I usually use the name of the submit button, but you could also have a hidden or visible field with a name that you use here.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points