Hola, tengo un pequeño problema. Espero me puedan dar una mano.
Tengo un flash en el cual incluyo un formulario, con 3 campos, nombre, localidad y mensaje. Una vez ingresados estos datos los envia a una db y lo levanto desde el mismo flash, el tema es que no me toma los puntos y aparte, toma todos los datos seguidos.
O sea, me gustaria que al hacerle enter, haga el punto y aparte, pero la verdad, no tengo ni idea.
Alguna ayudita?
Muchisimas gracias.
Codigos:
// Set text formatting colors for errors, waiting..., and success mechanisms
var errorsFormat:TextFormat = new TextFormat();
errorsFormat.color = 0xFF0000;
// hide the little processing movieclip
processing_mc.visible = false;
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
// Build the varSend variable
var varSend:URLRequest = new URLRequest("guestbookParse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
// Handler for PHP script completion and return
function completeHandler(event:Event):void{
// remove processing movieclip
processing_mc.visible = false;
// Clear the form fields
name_txt.text = "";
location_txt.text = "";
msg_txt.text = "";
// Load the response from the PHP file
status_txt.text = event.target.data.return_msg;
gbOutput_txt.condenseWhite = true;
gbOutput_txt.htmlText = "" + event.target.data.returnBody;
}
// Add an event listener for the submit button and what function to run
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
// Validate form fields and send the variables when submit button is clicked
function ValidateAndSend(event:MouseEvent):void{
// validate all the form fields
if(!name_txt.length) {
status_txt.text = "Bitte Name eingeben.";
status_txt.setTextFormat(errorsFormat);
} else if(!location_txt.length) {
status_txt.text = "Bitte location eingeben";
status_txt.setTextFormat(errorsFormat);
} else if(!msg_txt.length) {
status_txt.text = "Bitte geben Sie Ihre Nachricht ein.";
status_txt.setTextFormat(errorsFormat);
} else {
// All is good so send the message to the parse file
// Show the little "processing_mc" movieclip
processing_mc.visible = true;
// Ready the variables for sending
variables.comType = "parseComment";
variables.userName = name_txt.text;
variables.userLocation = location_txt.text;
variables.userMsg = msg_txt.text;
// Send the data to the php file
varLoader.load(varSend);
// Put a temporary message in the response field while the PHP file sends back
// If the code does not connect to the PHP file this message will remain visible to user
status_txt.text = "Waiting for server connection...";
} // close else after form validation
} // Close ValidateAndSend function ////////////////////
Codigo:
// This section of code gets all the comments for initial viewing
// Assign a variable name for our URLVariables object
var variables_re:URLVariables = new URLVariables();
// Build the varSend variable
var varSend_re:URLRequest = new URLRequest("guestbookParse.php");
varSend_re.method = URLRequestMethod.POST;
varSend_re.data = variables_re;
// Build the varLoader variable
var varLoader_re:URLLoader = new URLLoader;
varLoader_re.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader_re.addEventListener(Event.COMPLETE, completeHandler_re);
// Handler for PHP script completion and return
function completeHandler_re(event:Event):void{
// Load the response from the PHP file
if (event.target.data.returnBody == "") {
gbOutput_txt.text = "No data coming through";
} else {
gbOutput_txt.condenseWhite = true;
gbOutput_txt.htmlText = "" + event.target.data.returnBody;
}
}
// Ready any variables for sending
variables_re.comType = "requestEntries";
// Send the data to the php file
varLoader_re.load(varSend_re);
PHP: <?php
/*
::::::::::Script Written By: Adam Khoury @ www.developphp.com:::::::::::::
:::::::::If you find www.developphp.com tutorials helpful or handy:::::::::::::
:::::::::::please link to it wherever possible to help others find it::::::::::::::::
*/
// IMPORTANT!!!! Connect to MySQL database here(put your connection data here)
mysql_connect("rdbms.strato.de","U864017","t21a02a 13") or die (mysql_error());
mysql_select_db("DB864017") or die (mysql_error());
if ($_POST['comType'] == "parseComment") {
$name = $_POST['userName'];
$location = $_POST['userLocation'];
$comment = $_POST['userMsg'];
// Filter user input a little bit further using PHP if you allow more characters than I do in the Flash input text field
//$name = mysql_real_escape_string($name);
//$location = mysql_real_escape_string($location);
//$post = mysql_real_escape_string($comment);
// uncomment this line below to preserve line breaks, paragraphs and such in the comment text
//$post = nl2br(htmlspecialchars($comment));
// Add to DB
$sql = mysql_query("INSERT INTO guestbook (name, post_date, comment, location)
VALUES('$name', now(),'$comment','$location')")
or die (mysql_error());
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Assemble body and send back to flash showing their new comment or entry
$body = "";
$sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC");
while($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$name = $row["name"];
$post_date = $row["post_date"];
$comment = $row["comment"];
$location = $row["location"];
//$n_post_body = str_replace("<br />", "", $n_post_body); // Use in case you get too many line breaks when preserving breaks
$comment = stripslashes($comment);
$name = eregi_replace("'", "'", $name);
$location = eregi_replace("'", "'", $location);
$comment = eregi_replace("'", "'", $comment);
// Decode HTML entities if storing comments that preserve line breaks and such
//$n_post_body = html_entity_decode($n_post_body); // Uncomment to use
$post_date = strftime("%b %d, %y", strtotime($post_date));
$body .= '<u><b><font color="#790000">' . $name . '</font> | <font color="#9B9B9B">' . $location . '</font> | <font color="#9B9B9B">' . $post_date . '</font></b></u>
<br />
'.$comment.'
<br />
<br />
';
}
mysql_free_result($sql);
mysql_close();
// Echo into flash
echo "return_msg=Ihre Nachricht wurde erfolgreich gesendet, vielen Dank!&returnBody=$body";
exit();
} // close first if for post
if ($_POST['comType'] == "requestEntries") {
$body = "";
$sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC");
while($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$name = $row["name"];
$post_date = $row["post_date"];
$comment = $row["comment"];
$location = $row["location"];
$comment = stripslashes($comment);
// Decode HTML entities if storing comments that preserve line breaks and such
//$n_post_body = html_entity_decode($n_post_body); // Uncomment to use
$post_date = strftime("%b %d, %y", strtotime($post_date));
$body .= '<u><b><font color="#790000">' . $name . '</font> | <font color="#9B9B9B">' . $location . '</font> | <font color="#9B9B9B">' . $post_date . '</font></b></u>
<br />
'.$comment.'
<br />
<br />
';
}
mysql_free_result($sql);
mysql_close();
echo "returnBody=$body";
exit();
} // close first if for post
?>