Results 1 to 6 of 6

Thread: PHP Confirmation Box on Delete

  1. #1
    Join Date
    Feb 2010

    PHP Confirmation Box on Delete

    I have a Javascript function call on a link which pops open a ui dialog confirmation box and on confirmation uses ajax to delete a row in the database. This all works fine.

    However, I am questioning how to also code in some sort of php confirmation box IF javascript is turned off?

    I have this link
     <a href="#" onclick="delete_row('districts', '''. $district_id . "', 'district_id')">Delete</a>
    Then of course the js function which opens the dialog box and sends to ajax if delete is confirmed
    	function delete_row (db_table, id, field) {
    		$( "#dialog-confirm" ).dialog({
    			  resizable: false,
    			  width: 400,
    			  modal: true,
    			  buttons: {
    				"Delete": function() {
    						var parm_vals = 'table:'+db_table+',id:'+id+',field:'+field;
    						var datastring = 'func=delete_row&parms='+parm_vals;
    				 		/*call to ajax to delete the row*/
    						 type: 'POST',
    						 url : 'resources/ajax/ajax.php',	
    						 data: datastring,
    						 success : function(){
    				Cancel: function() {
    				  $( this ).dialog( "close" );
    The above code all works fine when using javascript and ajax.

    My questions are.....

    1) How do I code the delete link to go to the ajax.php page IF javascript is not turned on


    2) How do I get PHP to open the dialog box for confirmation?

    Thanks in advance for clarity on this.

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    Without JS you have no client control. That said, I would include a hidden field on your first page, put some js code in there to set that field to a value onload and then when the form is submitted for a delete, check (in php) if that field was set by JS. If not, you will have to retain the info re: the delete to be done, send a confirmation page via php and await its return and proceed as necessary. A bit more traffic than if JS was enabled, but it gets the job done. You might include some code in your php confirmation page to tell the user that JS would have made this process easier, in case he/she has deliberately disabled JS and can opt to re-enable it.

  3. #3
    Join Date
    Feb 2010
    I understand what you are saying, but I think there is some simple way in the link that I am missing.

    I think it should go something like this....

    $data .= '<a href="resources/ajax/ajax.php?func=delete_row&parms=table:user,id:6,field:id" onclick="if( delete_row(\'users\', \''. $user_id .'\', \'id\') ) { return false; }">
    So onclick, if javascript is on, the js function will be called which then will reload to the proper url.

    If javascript is not on, the js function will be ignored and not do anything so the href url will then be used and go to the appropriate page to parse the get variables.

    I hope this makes sense. Basically, make a js function call on click. If js is not enabled, the js function will be ignored, so then use the href to redirect the page.

    I've been trying forever to make this work.

    Is this possible?

    Thanks in advance.

  4. #4
    Join Date
    Jul 2013
    Voorheesville NY USA
    Sure - that approach works just fine. But - your original post asked how to get a PHP confirmation box when JS was not present. Your last post leaves that out of the equation.

    PS - I really don't know if your posted 'onclick' code was verbatim or some pseudo-code - it doesn't look viable to me. I also don't know how an onclick would respond if JS was not enabled.

  5. #5
    Join Date
    Feb 2010
    I appreciate your reply but my question wasn't answered.

    If a link looks like this,

    <a href="resources/ajax/ajax.php?func=delete_row" onclick="if( delete_row('users') is not ran because js is off ) { 'go to href link' }">
    If javascript is on, it goes to the href link and ignores the js function call.

    If javascript is off, it doesn't use the 'href' url.

    All I want to do is call a javascript function if javascript is on, and use the href url if javascript is off.

    How do I code that to do this?
    Last edited by waMP; 11-19-2013 at 04:56 PM. Reason: mis wording

  6. #6
    Join Date
    Jul 2013
    Voorheesville NY USA
    I thought you had answered your own question with your last post - except for the part about a PHP confirmation box which I pointed out that you hadn't addressed. I also pointed out that your onclick= doesn't look like anything I've seen.

    I'd use something like:
    <a href="(my url)" onclick="return deleteRow('somekeyvalue')">Click to Delete</a>
    where deleteRow is a js function in your page and 'somekeyvalue' is something to identify the row to be deleted by JS/AJAX.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11150 seconds
  • Memory Usage 2,891KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates