Jump to content


Photo

Button Query


  • Please log in to reply
3 replies to this topic

#1 Decarn

Decarn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 August 2006 - 09:30 AM

Hi Guys,

Instead of having two seperate buttons, I want to combine it to a single button.

<INPUT TYPE="submit" NAME="btn_H_Submit" OnClick="return confirm('Click Yes to update database and send an email or No to update database only');"  VALUE="Enter Information">

First question, when I click on the button, the pop up shows 'OK' and 'Cancel'. How do I change it to 'Yes' and 'No'?

Second, I want the 'Yes' button to update the database and send an email while the 'No' will only update the same database only (no email will be sent). Can it be done? A sample code on template on this will help me greatly.

Thanks.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 August 2006 - 10:40 AM

You cannot change the buttons in the confirm dialog box. Unless you create your own custom popup window.

For your secound question yes it can be done. However you'll have to get javascript to submit the form and add a url parameter called send and assign the value of 1 to it. Then in your PHP script you check whether the url has the send paramerter and is equal to 1, you send the email. If its not there is is not equal to 1 you dont send the email.

I'll some code in a sec.

Also this is more of a javascript question so I'll move this to the correct forum

The html:
< script type="text/javascript" >
// this function adds a url parameter which determins whether we send an email or not
function sendForm()
{
    // this gets our form
    // change yourFormName to the name of your form
    // if your form doesnt have a name set add
    // name="yourFormName" inside the form tag
    var form = yourFormName;

    // this variable holds TRUE if the user clicks OK or FALSE if the user clicks CANCEL.
    var sendEmail = confirm('Click Ok to update database and send an email or Cancel to update database only');

    // this si what adds the url parameter to the url
    // if the user clicks OK the we added ?send=1 to the url
    // if the user clicks CANCEL the we add send=0
    // this url parameter will be used by PHP to determin whether to send an email
    if(sendEmail) {
        form.action = form.action + '?send=1';
    } else {
        form.action = form.action + '?send=0';
    }
}
< /script >

<form action="test.php" name="yourFormName" method="post">
   Forname: <input type="text" name="name" /><br />
   Surname: <input type="text" name="surname" /><br />
   <input type="submit" name="btn_H_Submit" onclick="sendForm()" value="Enter Information" />
</form>
Have a read of the comments above for more info on whats going one (the comments are the double backslashes(//))

The PHP code:
<?php

// update the database here
echo "Update the database here<br /><br /><br />";

// Remeber the send url parameter that gets set with the javascript.
// This is where we determin whether to send an email!
// This checks whether the send url parameter exists and it is equal to 1
// if it is we send the email.
if(isset($_GET['send']) && $_GET['send'] == '1')
{
   // send email

   echo 'send an email tooo!!!';
}

?>


#3 Decarn

Decarn
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 23 August 2006 - 12:59 AM

Thanks wildteen88, I get the idea but I'm still a bit confused. Is there a sample tutorial or working code somewhere for reference?

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 August 2006 - 10:13 AM

That is the working code. What errors are you getting. What bit are you confused about.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users