1

I have formatted my form using uniform jquery plugin. Also for submitting the form i am using a link as i have added some effect to it and if I use input type submit for this it will get formatted with uniform .

<form>
      <ul>
        <li><label>Your Name:</label><input type="text" name="name" size="40"/></li>
        <li><label>Your Email:</label><input type="email" name="email" size="40"/></li>
    <li>
          <label>Gender:</label>
          <select name="gender">
            <option>Male</option>
            <option>Female</option>
            </select>
        </li>
    <li><label>Subject:</label><input type="text" name="subject" size="40"/></li>

    <li><label>Write your letter here:</label><textarea name="message" cols="60" rows="15"></textarea></li>
        OR ELSE<br/><br/>
        <li>
          <label>Upload your letter:</label>
          <input type="file" />
        </li>
        <li>
            <a id="mylink" class="button" href="#">
    <img src="button.png" alt="" />Send</a>


        </li>

      </ul>
    </form>

Now i want to submit this form using the link and also want to email it to two email ids simultaneously. What javascript code can i use. I am using the following code to submit the form and then in send.php I am sending the mail.

a.onclick = function() {
    $(this).parents('form:first').submit();
    send.php;

    return false;
}​

Is it possible to call send.php like this?

gdoron
  • 147,333
  • 58
  • 291
  • 367
Pooja
  • 736
  • 1
  • 13
  • 29
  • If you want to submit the form you'll need to give it an `action="yourURLhere"` attribute so that it knows where to submit to. Are you saying you want the form submitted somewhere different to send.php? Why? (You could have the php you submit to call send.php or do the emailing itself, no need for two requests from the browser.) – nnnnnn Jun 24 '12 at 09:01

2 Answers2

2

Do you mean:

If you have action="send.php" in your form, then

$(document).ready(function() {
    $("#mylink").click(function(e) {
        e.preventDefault();
        $(this).closest('form').submit();
    });
});

Or, you can set action for the form and submit, like

$(document).ready(function() {
        $("#mylink").click(function(e) {
            e.preventDefault();
                var myFrm = $(this).closest('form');
                myFrm.get(0).setAttribute('action', 'send.php');
            myFrm.submit();
        });
    });

OR, using ajax

$(document).ready(function() {
    $("#mylink").click(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "send.php",
            data: {your data to post here},
            succes: function(resp) {
                //your response here
            }
        });
    });
});
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1

Is it possible to call send.php like this?

Like this? No, you need to use ajax request:

$.ajax({
    url :"send.php"
});

Extra tip: change:

$(this).parents('form:first').submit();

To:

$(this).closest('form').submit();
gdoron
  • 147,333
  • 58
  • 291
  • 367
  • lol, `:))` mouse and keyboard was sitting someone thought what should we do :P < just guessing> – Tats_innit Jun 24 '12 at 09:07
  • LMAO indeed! `:)` hooked you up with `++1` for both; you should be rocking now :P (I knw) about that I just chill out now, `:)` a lot of times for some its a race then fun :P – Tats_innit Jun 24 '12 at 09:11