?
Solved

Ask for confirmation before posting

Posted on 2010-03-28
8
Medium Priority
?
496 Views
Last Modified: 2012-05-09
Hello

I am attempting to modify a bit of PHP inside a larger file.

Before the message gets posted, I want to request confirmation..and on confirmation the posting needs to continue. Or on cancelling, the posting is obviously cancelled.

Thanks

function onAfterContentSave( &$article, $isNew )
	{
		// post only published articles (publish date is not checked at the moment!), check for private articles
		if (($isNew	|| $this->post_modified)
			&& ($this->post_private || (!$this->post_private && (0 == $article->access)))
			&& (1 == $article->state))
		{
			$this->postMessage($article);
		}
		
		return true;
	}

Open in new window

0
Comment
Question by:MikeSel
6 Comments
 
LVL 6

Assisted Solution

by:V4nP3rs13
V4nP3rs13 earned 248 total points
ID: 28894347
here is the html
<input type="submit" value="Submit" onclick="return confirm(\'Are you sure you want to submit this article??\')" />
0
 
LVL 4

Author Comment

by:MikeSel
ID: 28898331
Sorry - perhaps I needed a bit more information. The above function is called in the background, and not off a button. The item is submitted the the database.

I am not trying to prevent this part from happening.

I am simply trying to get it to stop submitting to an additional location.

So it needs to call from inside the above function, like a Javascript alert if possible.

Thanks
0
 
LVL 2

Expert Comment

by:jmyeom
ID: 28900336
echo"<script language=javascript>youfunction();</script>"

maybe?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 83

Expert Comment

by:leakim971
ID: 28904452
Hello MikeSel,

The code you display is PHP running on server side.
Validation before posting is done on client side with the browser.

Regards.

Open in new window

0
 
LVL 4

Author Comment

by:MikeSel
ID: 28904752
Thanks

I understand what you are saying, the client side script fires another function from another file, saving the entry into the database.

That's also server side, im guessing Im not going to be able to do this without setting someform of flag at the very beginning and checking for that flag in the final server side script.

I wanted this script to prompt, then cancel any further processing at the point pasted above.
0
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 252 total points
ID: 28944412

There are two options:

1) Using a hidden field, as below

<script >1
function dosubmit(){

var retval=confirm(Are you sure want to commit?);

document.formname.userselected=retval;
document.formname.submit();

}
</script>

this hidden field will come under the form body
<input type=hidden name="userselected" />

in your PHP function update it as
//PHP script,
function onAfterContentSave( &$article, $isNew )
        {
          if(isset($_POST["userselected"]) && $_POST["userselected"]!=''){
                     
               //Remaining PHP function
          }
  }


2) Another option is to provide two buttons to user

<input type="submit" name="userselected" value="Confirm" />
<input type="submit" name="userselected" value="Cancel" />

in your PHP function update it as
//PHP script,
function onAfterContentSave( &$article, $isNew )
    {
         if(isset($_POST["userselected"]) && $_POST["userselected"] =='Confirm'){
                   
             //Remaining PHP function
         }

     }

Hope this helps...
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question