Problems with form submition

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Problems with form submition

 
0
  #1
Apr 3rd, 2008
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
  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
  1. if (isset($_POST['formname'])){
  2. \\ code goes here
  3. }
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: Problems with form submition

 
0
  #2
Apr 3rd, 2008
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.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: Problems with form submition

 
0
  #3
Apr 3rd, 2008
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?
  1. document.formname.submit();

P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Problems with form submition

 
0
  #4
Apr 3rd, 2008
You can actually have 2 submit buttons in a form. Eg.
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: Problems with form submition

 
0
  #5
Apr 3rd, 2008
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....
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Problems with form submition

 
0
  #6
Apr 3rd, 2008
Originally Posted by Venom Rush View Post
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?
  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).
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Problems with form submition

 
0
  #7
Apr 3rd, 2008
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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: Problems with form submition

 
0
  #8
Apr 3rd, 2008
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.....
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Problems with form submition

 
0
  #9
Apr 3rd, 2008
Exactly !
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: Problems with form submition

 
0
  #10
Apr 4th, 2008
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.
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC