Skip to content Skip to sidebar Skip to footer

Multiple Button Form Actions

I have this button that adds a user into a database from the fields they have entered. It works perfectly the only issue i have is. I need the new user details to be emailed to som

Solution 1:

You can use javascript onclick event like this:

<inputname="Submit"type="submit"id="Submit"value="Add New Contact"<?phpif($disable ==1){?>disabled<?php } ?>onclick="javascript:emailfunction();return true;"/></td></tr>

in the emailfunction(), you can manage the opening of a new email.

Solution 2:

Usually, this happens after your code already finishes adding the user data into database.

So the usual way:

  1. Sending data to your PHP code
  2. PHP inserts data into database
  3. If data successfully inserted, send an email with user details

If you send the data using JavaScript, before making sure they really were inserted to database, then you may face issues in the future of users claiming they get emails without really being their in website.

Now, as answer to your question, you can do whatever you want ( adding one or multiple actions to your button ), easily use something like ordinary JavaScript or even JavaScript framework like jQuery to add those actions, and I suggest your to convert your submit button into normal button.

Code example:

<inputtype="button"name="submitButton"value="Add New Contact"onclick="submitButtonClick()"><script>functionsubmitButtonClick() {
     // do whatever you want here line1// do whatever you want here line2// do whatever you want here line3document.getElementById('formId').submit();
    }
</script>

Post a Comment for "Multiple Button Form Actions"