Ask for confirmation before posting

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

LVL 4
MikeSelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

V4nP3rs13Commented:
here is the html
<input type="submit" value="Submit" onclick="return confirm(\'Are you sure you want to submit this article??\')" />
0
MikeSelAuthor Commented:
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
jmyeomCommented:
echo"<script language=javascript>youfunction();</script>"

maybe?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

leakim971PluritechnicianCommented:
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
MikeSelAuthor Commented:
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
Shinesh PremrajanEngineering ManagerCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.