gb.php til flash-gæstebog
Hej eksperterJeg er ved at lave en gæstebog i flash v.h.a. den sample macromedia har vedlagt flash8.
Men jeg kan se at når man poster en kommentar bliver det postet på en remote php-template, gb_insert.php-side som ligger på helpexamples.com. Det vil sige at alle andre der bruger samme sample skriver til den samme side... Hvordan laver jeg min egen php-template, så jeg kan undgå dette?
Koden ser ud som følger:
stop();
// import the required component classes.
import mx.controls.*;
// define the component instances on the Stage.
var name_ti:TextInput;
var email_ti:TextInput;
var url_ti:TextInput;
var comments_ta:TextArea;
var clear_button:Button;
var submit_button:Button;
var name_label:Label;
var email_label:Label;
var url_label:Label;
var comments_label:Label;
//set color of labels
name_label.setStyle("color", "0xFFFFFF");
email_label.setStyle("color", "0xFFFFFF");
url_label.setStyle("color", "0xFFFFFF");
comments_label.setStyle("color", "0xFFFFFF");
// set the tabbing order for the components
this.name_ti.tabIndex = 1;
this.email_ti.tabIndex = 2;
this.url_ti.tabIndex = 3;
this.comments_ta.tabIndex = 4;
this.clear_button.tabIndex = 5;
this.submit_button.tabIndex = 6;
// set the default form focus to the name_ti TextInput instance, and set the default button to the submit button.
Selection.setFocus(name_ti);
focusManager.defaultPushButton = submit_button;
// when the post_mc or view_mc movie clip's are clicked and released, goto the appropriate named frame label.
post_mc.onRelease = function() {
this._parent.gotoAndStop("post");
};
view_mc.onRelease = function() {
this._parent.gotoAndStop("view");
};
// when the clear button is clicked, set the form fields to empty strings.
var clearBtnListener:Object = new Object();
clearBtnListener.click = function(evt:Object) {
name_ti.text = "";
email_ti.text = "";
url_ti.text = "";
comments_ta.text = "";
};
this.clear_button.addEventListener("click", clearBtnListener);
// when the submit button is clicked, send the form values to the server using a LoadVars object.
var postBtnListener:Object = new Object();
postBtnListener.click = function(evt:Object) {
// if the name is blank, display an error message using the Alert component.
if (name_ti.text.length == 0) {
Selection.setFocus(name_ti);
Alert.show("Please enter your Name.", "Error", Alert.OK);
return false;
}
// make sure the user has filled in either the email_ti or url_ti TextInput instances.
if ((email_ti.text.length == 0) && (url_ti.text.length == 0)) {
Selection.setFocus(email_ti);
Alert.show("Please enter your Email Address or URL.", "Error", Alert.OK);
return false;
}
// make sure the comments_ta TextArea instance isn't blank.
if (comments_ta.text.length == 0) {
Selection.setFocus(comments_ta);
Alert.show("Please enter your Comments.", "Error", Alert.OK);
return false;
}
// if all the required fields have been filled in, create a LoadVars object instance and populate it.
var send_lv:LoadVars = new LoadVars();
send_lv.name = name_ti.text;
send_lv.email = email_ti.text;
send_lv.url = url_ti.text;
send_lv.comments = comments_ta.text;
send_lv.onLoad = function(success:Boolean) {
// if the comments were sent to the server and you received a response, clear the form fields and display an Alert message.
if (success) {
name_ti.text = "";
email_ti.text = "";
url_ti.text = "";
comments_ta.text = "";
Alert.show("Thank you for your comments.", "Success", Alert.OK);
} else {
// else you encountered an error while submitting to the server.
Alert.show("Unable to process your comments at this time.", "Server Error", Alert.OK);
}
};
// send the variables from Flash to the remote PHP template.
send_lv.sendAndLoad("http://www.helpexamples.com/flash/guestbook/gb_insert.php", send_lv, "POST");
};
this.submit_button.addEventListener("click", postBtnListener);
Håber i kan hjælpe! M.v.h. Iwersen
