943,884 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Apr 3rd, 2008
0

Problems with form submition

Expand Post »
Hi there

I have a form that I'm trying to submit but it just doesn't want to play nice.

The form i have has 2 submit buttons. One processes php code that updates info in a DB and the other deletes the info in the DB. The problem is that I have a popup asking for confirmation on the deleting and when I click ok nothing happens. All I need to know is how to submit my form using javascript so that it processes the PHP code to delete the DB entry.

form tag and delete button
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form name="formname" id="formname" method="post" action="<?= $_SERVER['PHP_SELF']?>" onSubmit="return checkWholeForm(this);">
  2.  
  3. <input onclick=\"confDelete()\" type="submit" name="delete" value="Delete">
  4.  

confirmation popup
javascript Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. function confDelete() {
  4. var answer = confirm("Msg")
  5. if (answer==true){
  6. document.formname.submit();
  7. return true;
  8. }
  9. }
  10. //-->
  11. </script>

Code that deletes DB entry
php Syntax (Toggle Plain Text)
  1. if (isset($_POST['formname'])){
  2. \\ code goes here
  3. }
Similar Threads
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Apr 3rd, 2008
0

Re: Problems with form submition

Hi,
you cant have two submit button on one form, do one thing:
have two simple button< input type="button" value="delete"......> and have on hidden field in form with name "task".On onclick event of these button call a function where you set the value of task="delete" or whatever you want, after this submit the form using javascript.
On server side check the value of task, according to value you take the action( either delete or add or....), one more thing in all cases you'll be having only one php page, where you will perform action according to "task" value.
Have a nice time !!!
Last edited by DangerDev; Apr 3rd, 2008 at 11:57 am.
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Apr 3rd, 2008
0

Re: Problems with form submition

DangerDev, My problem is that I don't know javascript very well and haven't been able to find any solutions. Is the section of code for submitting the form correct?
javascript Syntax (Toggle Plain Text)
  1. document.formname.submit();

P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Apr 3rd, 2008
0

Re: Problems with form submition

You can actually have 2 submit buttons in a form. Eg.
php Syntax (Toggle Plain Text)
  1. <?php
  2. if($_POST['submit1']) {
  3. echo "Submit1 pressed! Add/update the records";
  4. }
  5. if($_POST['submit2']){
  6. echo "Submit2 was pressed ! Now delete the records !";
  7. }
  8. ?>
  9. <html>
  10. <head>
  11. <script type='text/javascript'>
  12. function confirmdel() {
  13. var val = confirm("Do you really want to delete ?");
  14. if(val) {
  15. return true;
  16. } else {
  17. return false;
  18. }
  19. }
  20. function calltest() {
  21. alert("Hi there!");
  22. return true;
  23. }
  24. </script>
  25. </head>
  26. <body>
  27. <form method="post" action="thispage.php" onsubmit="javascript: return calltest();">
  28. <input type="submit" name="submit1" value="add"><input type="submit" name="submit2" value="delete" onclick="javascript: return confirmdel();">
  29. </form>
  30. </body>
  31. </html>
But, since both the buttons are submit buttons, onSubmit event will be fired when you click either of the buttons.
Last edited by nav33n; Apr 3rd, 2008 at 12:13 pm.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 3rd, 2008
0

Re: Problems with form submition

yes it is correct, but when you are submitting how you are making difference at server side(of which button user has clicked), if you have problem in that see my suggested solution....
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Apr 3rd, 2008
0

Re: Problems with form submition

Click to Expand / Collapse  Quote originally posted by Venom Rush ...
DangerDev, My problem is that I don't know javascript very well and haven't been able to find any solutions. Is the section of code for submitting the form correct?
javascript Syntax (Toggle Plain Text)
  1. document.formname.submit();

P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
Since you are already using the submit button in your form, you can't submit that way (I think).
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 3rd, 2008
0

Re: Problems with form submition

DangerDev, you can know which button was pressed by giving each button a unique name. In my example, I have called it submit1 and submit2.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 3rd, 2008
0

Re: Problems with form submition

Quote ...
I have called it submit1 and submit2.
yes i got it, i just forgot it, any way thanks,,,
then there is no problem at all, you can check at server side the name of button and on the base of this you can have intended functionality.....
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Apr 3rd, 2008
0

Re: Problems with form submition

Exactly !
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 4th, 2008
0

Re: Problems with form submition

so is there a way i can call the delete submit button with javascript?

eg. document.formname.submitButtonName.submit();
Last edited by Venom Rush; Apr 4th, 2008 at 3:35 am.
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Need help in javascript and modal window
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: form working in IE not Firefox -why?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC