PDA

View Full Version : Need PHP Code



Drugs
08-08-2006, 08:45 PM
I need a PHP code so if someone typed in nothing in a field, it makes a JavaScript popup saying 'Please enter a message' or something.

Correctable (Forum Moderator) - Thread moved to Coding. Please post in the correct sections.

Fujitsu
08-08-2006, 08:47 PM
Try something like

if($message == "") { echo "You haven't entered a message"

Drugs
08-08-2006, 08:47 PM
Thanks will try.

Edit: Thats not a complete code, the echo tag looks uncompleted.

Fujitsu
08-08-2006, 08:53 PM
You could try a javascript. In your form code put


<form name="shoutbox" onsubmit="return validate()">

then in the HEAD tag of your page put


<SCRIPT>function validate() {
with (document.form1) {
var alertMessage = "The following field is empty:\n";
if (name.value == "") {
alertMessage += "\name" }
if (message.value == "") {
alertMessage += "\message" }
if (alertMessage != "The following field is empty:\n") {
alert(alertMessage);
return (false);
}
return (true)
}
}</SCRIPT>

Drugs
08-08-2006, 08:55 PM
Sorry for double post ;P

I used the following code;

if ($name == "") {
echo "Please enter a Name";
}

But when it comes up with "Please enter a name" it just redirects to the shoutbox and still submits the message.

Sygon.
08-08-2006, 08:58 PM
Just do:




if(!$name) {

echo "

<script language='javascript'>

alert('Fill in your name');

</script>

";

}

Fujitsu
08-08-2006, 08:59 PM
Try


<?php echo("Wouldn't Work, Code Removed"); ?>


But looking at Sygon's code, that should work.

Drugs
08-08-2006, 08:59 PM
Sygon i used that but go to the site and type something in with no name..

When you press ok on the alert, it just goes back to the shoutbox and types it in anyway.

Fujitsu still typed it in anyway

ClubTime
08-08-2006, 08:59 PM
Wrong section :)

Correctable (Forum Moderator) - Please do not post pointlessly acting like a moderator.

Fujitsu
08-08-2006, 09:02 PM
@ Chris

So, does it really matter?

Correctable (Forum Moderator) - Please stay on topic

Drugs
08-08-2006, 09:03 PM
No one looks at codes >.>

And anyone who wants to help me add me to MSN *REMOVED* ;D

Correctable (Forum Moderator) - Do not give out personal information!

Fujitsu
08-08-2006, 09:03 PM
Maybe something in your code you already have is interfering with it and making it send the message anyway.

ClubTime
08-08-2006, 09:05 PM
Yes, there is a section for coding :P

Drugs
08-08-2006, 09:05 PM
This is what i have now..



<?php

$name = $_POST['name'];
$message = $_POST['message'];

$tag = ("<font size=\"1\" face=\"verdana\">
<b>$name</b>; $message
</font><br><br>");

$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);

$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);

print "<meta http-equiv=\"refresh\" content=\"0;shoutbox.php\">";

if(!$name) {

echo "

<script language='javascript'>

alert('Fill in your name');

</script>

";

}

?>

Drugs
08-08-2006, 09:06 PM
Ooooh i know brb.

Nvm.

Edited by ---MAD--- (forum moderator): Please do not pointless post, thanks :)

Fujitsu
08-08-2006, 09:06 PM
Because it's refreshing before the Javascript is sent.

Drugs
08-08-2006, 09:09 PM
Hmm so post the code which should work then pls.

Fujitsu
08-08-2006, 09:09 PM
Try:



<?php

$name = $_POST['name'];
$message = $_POST['message'];

$tag = ("<font size=\"1\" face=\"verdana\">
<b>$name</b>; $message
</font><br><br>");

$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);

$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);

if(!$name) {

echo "

<script language='javascript'>

alert('Fill in your name');

</script>

";
}

else {

print "<meta http-equiv=\"refresh\" content=\"0;shoutbox.php\">";

}
}

?>

ClubTime
08-08-2006, 09:11 PM
that wont work. theres a little error



Try:






<?php



$name = $_POST['name'];

$message = $_POST['message'];



$tag = ("<font size=\"1\" face=\"verdana\">

<b>$name</b>; $message

</font><br><br>");



$read = fopen("content.txt", "r");

$contents = fread($read, filesize('content.txt'));

fclose($read);



$write = fopen("content.txt", "w");

fwrite($write, "$tag $contents");

fclose($write);



if(!$name) {



echo "



<script language='javascript'>



alert('Fill in your name');



</script>



";

}



else {



print "<meta http-equiv=\"refresh\" content=\"0;shoutbox.php\">";



}




?>



oops lost the error :)

Sygon.
08-08-2006, 09:12 PM
Make sure you use some sort of frame to display the input and output seperatly

bob
08-08-2006, 09:13 PM
Make sure you use some sort of frame to display the input and output seperatly
Like an iframe?

Drugs
08-08-2006, 09:14 PM
Fujitsu, still dont work, it just loads a blank page, but stil submits to the shoutbox

Edit: If someone could just type out the whole code and make it work i would be greatful..

Also why i am here, could anyone post a code to disable HTML in the form fields ;P

bob
08-08-2006, 09:21 PM
Lolz, coz i pwnt it :p

Fujitsu
08-08-2006, 09:21 PM
In your HEAD tag add



<script type="text/javascript">
function blank () {
var name = document.FORMNAME.FIELD NAME;
var message = document.FORMNAME.FIELD NAME;

if (name.value == "") {
window.alert("Please fill in your name.");
}

if (message.value == "") {
window.alert("Please fill in a message.");
}
}
</script>


And In Your <input> tag add



onclick="blank();"


The code I posted before wouldnt work, so I edited it.

Drugs
08-08-2006, 09:23 PM
Fujitsu and in which file am i putting that in?

ClubTime
08-08-2006, 09:24 PM
Lmao you really havent got a clue have you :)

Drugs
08-08-2006, 09:25 PM
I presume in the shoutbox.php file but i am jsut making sure.

bob
08-08-2006, 09:27 PM
Yeh, it is.

Fujitsu
08-08-2006, 09:28 PM
Yes. *Longer Post*

Drugs
08-08-2006, 09:29 PM
For this bit;

onclick="blank();"

Where do i put that??

ClubTime
08-08-2006, 09:30 PM
For this bit;

onclick="blank();"

Where do i put that??

Lol :) this is fairly amusing :)

Fujitsu
08-08-2006, 09:31 PM
In your <INPUT> Tag

Muhammad Haris
08-08-2006, 09:31 PM
This code is really broken up for shoutbox, Please check your other thread where I have posted a comment. You should really check it out.

Drugs
08-08-2006, 09:32 PM
Which input tag...

ClubTime
08-08-2006, 09:34 PM
Ryan scrap it and find another one.

Fujitsu
08-08-2006, 09:35 PM
<INPUT TYPE="Submit" name="submit" value="Submit Your Shout" size="20">

G2G Help Tomorrow

Muhammad Haris
08-08-2006, 09:36 PM
Drugs, I'm posting a fix which will have every feature you have request in this thread. Just wait for a few minutes! :)

Drugs
08-08-2006, 09:36 PM
Chris if you can find another one that is simple like this then i will scrap it, and one that is fully customisable

Edit; OK thanks Muhammad

ClubTime
08-08-2006, 09:43 PM
:) http://myshoutbox.com

Ryan in addtag.php change:



print "<meta http-equiv=\"refresh\" content=\"0;shoutbox.php\">";


to:


print "<meta http-equiv=\"refresh\" content=\"0:shoutbox.php\">";

Drugs
08-08-2006, 09:44 PM
Nooo LMAO

I want a simple, plain one like this, where it is fully customisable, the forum seperated from the actual shoutbox like my one now.

ClubTime
08-08-2006, 10:11 PM
theres a shoutbox one techtuts aint there?

Drugs
08-08-2006, 10:14 PM
Techtuts one is crap this one is going well now.

ClubTime
08-08-2006, 10:20 PM
Did my script work? :)

Drugs
08-08-2006, 10:20 PM
Its going well ATM ;D

ClubTime
08-08-2006, 10:21 PM
What my one i posted?

Drugs
08-08-2006, 10:37 PM
Oh, no lmao Muhammad is helping me ;D

Sygon.
08-08-2006, 11:16 PM
Im helping on msn > Whos helping you >

Drugs
08-08-2006, 11:26 PM
Muhammad was but were stuck add [email protected] i am really stuck

Muhammad Haris
08-08-2006, 11:29 PM
Muhammad was but were stuck add [email protected] i am really stuck

The system needs a database to store variable individually so you can impliment codes easily otherwise txt file based won't work at all as it is currently coded by the scripter.

Drugs
08-08-2006, 11:30 PM
Its gotta somehow..

Edit: I have seen it on non-mysql based stuff before.

Muhammad Haris
08-08-2006, 11:31 PM
Its gotta somehow..

Edit: I have seen it on non-mysql based stuff before.

Can I have a link of few please?

Drugs
08-08-2006, 11:32 PM
I dont have them at hand, i was just mentioning i have seen it before.

Sygon.
08-08-2006, 11:39 PM
Muhammad was but were stuck add [email protected] i am really stuck

I was helping muhamed when he asked me questions :rolleyes:

Drugs
08-08-2006, 11:43 PM
Oh i see..

Anyway sygon reckon you can do it? It needs to not be able to use HTMl..

Mentor
08-08-2006, 11:44 PM
Stupid use of php, far better done with some simple Js "/

Want to hide these adverts? Register an account for free!