You are not logged in.
Pages: 1
Xinha has been a great asset on our small CMS project, so thanks to all contributing. I'm a designer and novice developer working with a freelance PHP coder. I'm trying to solve this issue before I consult him ($).
Our "Insert Story" page gives users a message if a field and/or textarea is unfilled. With Xinha, the message does not appear if the textarea is unfilled. But when I disable Xinha in the code and the textarea is unfilled, the message displays normally. Other unfilled form fields on the page always show a message, if Xinha is on or off.
Reading other posts, seems that Xinha typically has little impact on such functionality, yet, here we are. I've posted the basic code to see if anything stands out that will gently nudge me in the right direction. Thanks...
<body>
<?php
if (isset($_POST['submit'])) {
$message = NULL;
// Check for a head.
if (empty($_POST['newshead'])) {
$h = FALSE;
$message .= 'You forgot to enter a headline!<br />';
} else {
$h = ($_POST['newshead']);
}
// Check for a story.
if (empty($_POST['newstext'])) {
$t = FALSE;
$message .= 'You forgot to enter story text!';
} else {
$t = ($_POST['newstext']);
}
if ($d && $h && $t) {
$query = "INSERT INTO strivenews (newshead, newstext) VALUES ('$h', '$t')";
$result = @mysql_query ($query);
mysql_close();
}
}
?>
<div id="content">
<?php if (isset($result)) {
include 'successpub.php';
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="insertstory">
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="35" colspan="3" valign="top"><h2>Insert A New Story</h2></td>
</tr>
<tr>
<td height="50" width="100">Headline:</td>
<td colspan="2"><input type="text" name="newshead" id="newshead" value="<?php if (isset($_POST['newshead'])) echo stripslashes($_POST['newshead']); ?>" size="50" maxlength="75" /></td>
</tr>
<tr>
<td width="100" valign="top">Story:</td>
<td colspan="2"><textarea id="newstext" name="newstext" width="450px" height="350px"><?php if (isset($_POST['newstext'])) echo stripslashes($_POST['newstext']); ?></textarea></td>
</tr>
<tr>
<td width="100"></td>
<td colspan="2">
<?php
}
if (isset($result)) {
} else {
if (isset($message)) {
echo '<br /><b><font color="red">', $message, '</font></b><br />';
}
print '<table width="460" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="350"><p> </p><input name="submit" type="submit" id="submit" value="Publish New Story" /></td>
<td width="110">Cancel</td>
</tr>
</table>';
}
?>
</td>
</tr>
</table>
</form>
</div>
</body>
Offline
That's because in most cases even if theres apparently notthing in the WYSIWYG area, the return is not really empty.
Unfortunately there are a bunch of different things that can be inserted there, ranging from a simple linebreak to a <br /> or a empty paragraph with a nonbreaking space, so it's a not too trivial task to check epmty.
I have quickly put this together for a starter, but no guarantee that it works in 100% of cases
if (preg_replace('/\s| /','',strip_tags($_POST['newstext'])) =='') {
Offline
That's brilliant ray, just tested and it works... many thanks!
Offline
I'm using this kind of approach but unfortunatly on some cases, as stated by Ray, you will find a false empty.
This will be considered empty
<p><a href="xxx"><img src="xxx"></a></p>
Last edited by mokhet (2006-09-21 18:38:36)
Offline
Yeah, that's right.
Then it would probably be better to strip out br's and p's specifically
if (preg_replace('/\s| |<\/?p>|<br \/>/','',$_POST['newstext']) =='') {
Last edited by ray (2006-09-22 09:45:38)
Offline
OK…here comes a big time newbie question…
I definitely want to try to implement Ray’s new suggestion (since it sounds brilliant!), but I’m not sure where to put that ‘if’ string.
At the top of my page in the <head> section I have this:
--
<script type="text/javascript">
_editor_url = "http://website.com/owners/xinha/";
_editor_lang = "en";
</script>
<script type="text/javascript" src="http://website.com/owners/xinha/htmlarea.js"></script>
<script type="text/javascript" src="http://website.com/owners/xinha/my_config.js"></script>
<link type="text/css" rel="stylesheet" title="blue-metallic" href="http://website.com/owners/xinha/skins/xp-blue/skin.css">
--
Then, lower down on the page I have my text area:
--
<textarea name="td-BODY_TEXT-value" id="td-BODY_TEXT-value" rows=20 cols=55 style="width: 500px;">Default Text<textarea>
--
But, that’s pretty much it.
I’m not sure if it makes a difference, but often times I have multiple text area on the page with different names/IDs.
If someone can give me a push in the right direction and tell me what to add to give this solution a try, I would greatly appreciate it!
(Again, sorry for the clearly newbie question!)
Thanks!
Last edited by rburko (2006-09-22 10:38:46)
Offline
rburko: Ray's code has to be inserted in the PHP script that processes the form, it's not in HTML page source. You most likely have the path to this script in action attribute of the form element (<form action="path_to_script.php">).
Hovever it still requires some PHP knowlegde to be able to insert the code in the right place within the script.
Offline
rburko... the code in my initial post is working and may show you how our page is set up, more or less. I just inserted the aforementioned brilliant code in place of
if (empty($_POST['newstext'])) {
Offline
Pages: 1