Hi folks, I have this site and idea http://www.helraizer.co.uk/mychatbox/
at the moment I'm using javascript to alert the user if they haven't entered a username or message but all this does is popup an alert message and return false. However, if their browser does not support javascript (javascript is turned off) then it just won't send and will give them no reason why.
How would I get it so that, using php, if the submit button is pressed and either the username is less than 3 characters and/or the comment field is less than 5 characters then above the image (on the site page) a list of errors would appear.
So if nothing was wrong it shows no errors but if the user name was less than 3 characters and comment <5 it'd appear
"Error!
-Your username is too short, please enter a user name between 3 and 10 characters.
-Your comment is too short, please enter a comment between 5 and 75 characters." (or similar)
How would I do this?
I know this is a "help" forum not a "do it for me forum" but if you guys can give me a baseline for this problem, to work with from there I can probably get it from there. =)
Thanks,
Sam
2 2569
PHP can not make an alert box, but it can print an error to the page.
are your boxes submitting to an input page, if so i would suggest looking at the php function strlen(). pass both inputs through this, and it its less than what is expected die() your error.
example:
[PHP]$str1 = "Apple";
$str2 = "Banana";
$len1 = strlen($str1);
$len2 = strlen($str2);
if($len1 < 6) {
die('Apple is less than 5 chars.');
}
if($len2 < 4) {
die('Banana is less than 4 chars.');
}[/PHP]
so if you want to figure it out there you go, if not ask and ill work it into your code.
PHP can not make an alert box, but it can print an error to the page.
are your boxes submitting to an input page, if so i would suggest looking at the php function strlen(). pass both inputs through this, and it its less than what is expected die() your error.
example:
[PHP]$str1 = "Apple";
$str2 = "Banana";
$len1 = strlen($str1);
$len2 = strlen($str2);
if($len1 < 6) {
die('Apple is less than 5 chars.');
}
if($len2 < 4) {
die('Banana is less than 4 chars.');
}[/PHP]
so if you want to figure it out there you go, if not ask and ill work it into your code.
Hey Eragon, thanks for that. I worked out a solution for the problem =)
This is the php code I used, it seems to work with out any bugs so far, could you let me know if it's good enough or if there is any way it could be improved? -
<?php
-
-
unset($errors);
-
-
include("linesfile.php5");
-
$filename = "data.line";
-
set_magic_quotes_runtime(0);
-
-
if($_POST['submit'] && strlen($_POST['input']) < 5) {
-
$errors[] .= _NO_5;
-
}
-
if($_POST['submit'] && strlen($_POST['username']) < 3) {
-
$errors[] .= _NO_2;
-
}
-
-
?>
-
<div class="ddgb_entrybox">
-
<table width="100%" border="0" cellspacing="8" cellpadding="0">
-
<tr>
-
<td width="42%" align="right" valign="top"></td>
-
<td align="left" valign="top">
-
<?php
-
-
if(isset($_POST['submit']) && $errors[0] != null) {
-
echo "<h2>" . _ERROR . "</h2><ul>";
-
foreach ($errors as $f) {
-
echo "<li>" . $f . "</li>";
-
}
-
echo "</ul>";
-
}
-
-
elseif($_POST['submit']) {
-
// grab the inputted text
-
$text = htmlspecialchars(stripcslashes($_POST['input'] . "\n"));
-
$username = htmlspecialchars(stripslashes($_POST['username']));
-
$color = $_POST['color'];
-
$font = $_POST['font'];
-
$ip = $_SERVER['REMOTE_ADDR'] . "\n";
-
$_SESSION['username'] = $username;
-
$_SESSION['color'] = $color;
-
$dirty = array(); // dirty words here, I removed them to keep this thread clean
-
-
foreach($dirty AS $bad_word){
-
$text = preg_replace("/$bad_word/i","****", $text);
-
}
-
-
-
-
-
-
-
$data[] ="\n". htmlspecialchars_decode(substr($username,0,10));
-
$data[] =trim($color);
-
$data[] =trim($font);
-
$data[] =htmlspecialchars_decode(trim(substr($text,0,75)));
-
-
-
$datafile = new DataFile($filename);
-
if(!$datafile->writeNewLine($data)) die("Error writing to file");
-
-
-
-
-
-
}
-
-
?>
-
_ERROR
_NO_5
_NO_2
have all been defined in a different document.
Sam
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: monika |
last post by:
I am not clear ... whether to use alert of JavaScript or messagebox of
VBScript in ASP. But what I want is that when a user has some error I want
to display a pop-up kind of a thing saying "you have not entered all the
values" ... and when he click "ok" then he should be directed to the same
page where he was entering the values. I tried this but in my case I am just
being redirected to the page ..and my message box in not being popped up!...
|
by: Justin Koivisto |
last post by:
Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something else.
--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
|
by: elaines |
last post by:
I can't seem to get this to work. Any help appreciated. The alert
message always comes up.
Here is my code
<SCRIPT type="text/javascript">
function fte()
{
var hours = document.form1.hours.value //get user input for hours
var weekdays = document.form1.weekdays.value //get user input for days
|
by: bonehead |
last post by:
Greetings,
I'm working on an e-mail form (btw many thanks to Philip Ronan for the
very cool email address format tester function, best I've seen so far).
I've been trying, with limited success, to produce a javascript alert
box which shows the user a validation error message. The error message
itself is dynamic, i.e., it's contained within a php variable.
I seem to be running into two issues:
|
by: Tom |
last post by:
I am having a really annoying issue with serialization and a .NET User
Control I am writing. For example, let's say I have a couple of classes in
my control - first class is like:
Public Class User
Private _UserName As String
Private _UserCity As String
<System.ComponentModel.CategoryAttribute("User Info")> _
Public Property UserName() As String
Get
| |
by: simon |
last post by:
hello.
hopefully another quick newbie question for you....
I have a codebehind function coded to handle the click event of a
button. what this function does is insert values from a data grid
into the database. after that is done i want to send the user to
PageC, but before i do that i check a variable value. if that value
is "0" then i want to raise a javascript alert telling the user they
need to set some info in PageA and then...
|
by: jehugaleahsa |
last post by:
Hello:
I am going through an effort to standardize web applications for my
company. We are trying to figure out the best practices for security,
error handling, etc. I've just done a large amount of work to figure
out the built-in ASP .NET security features (which was fairly easy to
do). So now I am tackling error handling.
What we would like to do is show a JavaScript Alert box with the error
information in it. Here is the code I...
|
by: Jonathan N. Little |
last post by:
As part of a JavaScript precheck form validation I noticed a problem
with trying to return focus to the field with an error. I have setup a
demo page.
http://www.littleworksstudio.com/temp/usenet/focus.html
To simulate the problem, just enter or change the "first" textbox and
either click or tab to another control., it is tied to the onchange
event. An alert box that simulates the "warning". When you close it the
focus will not move...
|
by: bonneylake |
last post by:
Hey Everyone,
well was hoping if someone could explain to me how to add an alert for the description fields of this multiple attachments script. The problem i think i am having is i don't know how to make it check multiple fields to make sure each field has been checked for a description before submitting. Here is what i have
on my form page
<input type="file" name="attachment1" id="attachments" value="1"...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |