| | |
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 |
•
•
•
•
eg. document.formname.submitButtonName.submit();
php Syntax (Toggle Plain Text)
<?php print_r($_POST); ?> <html> <head> <script type="text/javascript"> function delsubmit() { var conf; conf=confirm("Are you sure ?"); if(conf) { document.test.submit(); } else { return false; } } </script> </head> <body> <form name="test" method="post" action="<?php echo $PHP_SELF; ?>"> <input type="text" name="name" value="1"> <input type="button" name="button" value="Delete" onclick="javascript: return delsubmit();"> </form> </body> </html>
php Syntax (Toggle Plain Text)
<?php print_r($_POST); ?> <html> <head> <script type="text/javascript"> function delsubmit() { var conf; conf=confirm("Are you sure ?"); if(conf) { document.test.submit(); } else { return false; } } </script> </head> <body> <form name="test" method="post" action="<?php echo $PHP_SELF; ?>"> <input type="text" name="name" value="1"> <input type="submit" name="submit" value="add"> <input type="button" name="button" value="Delete" onclick="javascript: return delsubmit();"> </form> </body> </html>
php Syntax (Toggle Plain Text)
<?php print_r($_POST); ?> <html> <head> <script type="text/javascript"> function delsubmit() { var conf; conf=confirm("Are you sure ?"); if(conf) { document.test.submit(); } else { return false; } } </script> </head> <body> <form name="test" method="post" action="<?php echo $PHP_SELF; ?>"> <input type="text" name="name" value="1"> <input type="button" name="button" value="add" onclick="javascript: document.test.submit();"> <input type="button" name="button" value="Delete" onclick="javascript: return delsubmit();"> </form> </body> </html>
If you still have problems, let me know!
Cheers,
Naveen
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Thanks for that nav33n. Slowly getting somewhere, the form is submitting but it's not actually executing the php code. Is my php code below correct?:
PHP Syntax (Toggle Plain Text)
if (isset($_POST['FormName'])) {
This user has a spatula. We don't know why, but we are afraid.
Nope.. $_POST['formname'] will not hold any value. You can do it this way (again, as DangerDev mentioned), have a hidden variable (task). When you click on 1st button, assign a value to task variable.
document.formname.task.value='add'; Similarly, assign another value when another button is clicked. document.formname.task.value='delete'; Then you can check what value task variable holds. php Syntax (Toggle Plain Text)
if($_POST['task']=="add"){ //add } if($_POST['task']=="delete"){ //delete }
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Still having problems executing the php code. this is what I have so far:
Javascript for setting the task value to del and then submitting the form
The hidden "task" field and the delete button
If task has the value of del then execute PHP code
My second button is set up in a similar way. Right now neither of them execute the required PHP code.
Javascript for setting the task value to del and then submitting the form
javascript Syntax (Toggle Plain Text)
function confDelete() { var answer = confirm("Are you sure") if (answer){ document.formName.task.value=='del'; document.formName.submit(); } else { return false; } }
The hidden "task" field and the delete button
PHP Syntax (Toggle Plain Text)
<input type="hidden" name="task" id="task" value=""> <input onclick="javascript: return confDelete();" type="button" name="delete" value="Delete">
If task has the value of del then execute PHP code
PHP Syntax (Toggle Plain Text)
if ($_POST['task']=="del"){ // execute code }
My second button is set up in a similar way. Right now neither of them execute the required PHP code.
This user has a spatula. We don't know why, but we are afraid.
•
•
Join Date: Mar 2008
Posts: 154
Reputation:
Solved Threads: 19
You would do far better not to rely on javascript for this at all. Instead you should parse the post with PHP and from that display a confirmation for the delete if delete was selected. That is simply good coding practice.
It is common to use javascript for error checking (I do myself) however the form should still submit and also be checked with PHP if javascript is disabled.
Matti Ressler
Suomedia
It is common to use javascript for error checking (I do myself) however the form should still submit and also be checked with PHP if javascript is disabled.
Matti Ressler
Suomedia
Last edited by Suomedia; Apr 4th, 2008 at 10:23 pm.
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
Relying on Javascript to deliver the business functionality is dangerous to the business which you are trying to cater. If this is some school project, it doesn't matter anyways but if this is for real, you need to start rethinking your design and add a server side check for such critical functionality.
Last edited by ~s.o.s~; Apr 6th, 2008 at 2:25 pm.
I don't accept change; I don't deserve to live.
Thanks nav33n. Got it working. 
Suomedia, ~s.o.s~...Thanks for your comments. I realize javascript could be switched off on some machines and would never use this kind of functionality if it was being used by the public. It's a simple admin system that's only going to be used by one person.

Suomedia, ~s.o.s~...Thanks for your comments. I realize javascript could be switched off on some machines and would never use this kind of functionality if it was being used by the public. It's a simple admin system that's only going to be used by one person.
This user has a spatula. We don't know why, but we are afraid.
![]() |
Similar Threads
- IE7 sucks!!!! (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Need help in javascript and modal window
- Next Thread: form working in IE not Firefox -why?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate automatically beta box bug calendar captcha cart checkbox child class column cookies createrange() css cursor decimal design dom download dropdown editor element engine enter error events explorer file focus form forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jump listbox math matrixcaptcha menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype rated rating regex runtime scale scroll search select session shopping size sql star starrating stars text textarea validation w3c web website window windowofwords windowsxp wysiwyg xml \n






