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:
<input name="Submit" type="submit" id="Submit" value="Add New Contact"
<?php if($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:
- Sending data to your PHP code
- PHP inserts data into database
- 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:
<input type="button" name="submitButton" value="Add New Contact" onclick="submitButtonClick()">
<script>
function submitButtonClick() {
// do whatever you want here line1
// do whatever you want here line2
// do whatever you want here line3
document.getElementById('formId').submit();
}
</script>
Post a Comment for "Multiple Button Form Actions"