PDA

View Full Version : field value?



Illkillutill
06-04-2010, 09:20 AM
How do you get the value of a form text field when somebody types it in?

The value is blank...

<input type="text" name="txt1" value="">


in the form, they type in "Illkillutill"...

how do i get the Illkillutill?

Zyt3x
06-04-2010, 09:22 AM
You have to set "action" and "method". :)

Let me get you a tutorial...
http://www.w3schools.com/php/php_forms.asp

Illkillutill
06-04-2010, 09:29 AM
Well, I was hoping just to put it in a javascript variable. i have this... but it doesn't work...



<script type="text/javascript">
var theText = document.form1.txt1.value;
</script>

Frement
06-04-2010, 09:34 AM
Something like:

<script type="text/javascript">
var theText = document.getElementByName("txt").value;
</script>

Illkillutill
06-04-2010, 09:37 AM
still keeps coming up with an undefined :(

Frement
06-04-2010, 09:48 AM
still keeps coming up with an undefined :(


<html>

<body>
<input type="text" name="txt1" id="txt1" value="fail" />
<script type="text/javascript">
document.write(document.getElementById("txt1").value);
</script>
</body>

</html>

Illkillutill
06-04-2010, 06:19 PM
Ok, i have this, but it doesn't take me to the new page...


<html>
<body>

<FORM>
<label>What would you like to look up?</label><br><input type="text" id="txt1" value="">

<script type="text/javascript">

function OpenLog(txt)
var theText = document.getElementById("txt1").value;
{
if (theText == "")
{
alert("No information was entered");
return false; }
else
{
parent.location='http://thewebsite.com'+ theText;
return true; }
}

</script>

<INPUT TYPE="button" value="Submit" onclick="return OpenLog(txt1)">
</FORM>

</body>
</html>

i luffs yeww
06-05-2010, 06:19 AM
Ctrl + Shift + J in FF? :)

Error: syntax error
Source File: file:///home/ian/Desktop/new%20file
Line: 10
Source Code:
var theText = document.getElementById("txt1").value;

^ When loaded.

Error: OpenLog is not defined
Source File: file:///home/ian/Desktop/new%20file
Line: 1

^ After submitting.

Frement
06-05-2010, 07:06 AM
<html>
<body>

<FORM>
<label>What would you like to look up?</label><br><input type="text" id="txt1" value="">

<script type="text/javascript">

function OpenLog(txt)
var theText = document.getElementById(txt).value;
{
if (theText == "")
{
alert("No information was entered");
return false; }
else
{
parent.location='http://thewebsite.com'+ theText;
return true; }
}

</script>

<INPUT TYPE="button" value="Submit" onclick="return OpenLog('txt1')">
</FORM>

</body>
</html>

rogeruk
06-05-2010, 09:51 PM
<?php
if (isset($_POST['submit'])) {
$name = $_POST["name"];
echo "Hello, " . $name;
}else{
?>
<html>
<head>
<title>My Form</title>
</head>
<body>
<form method="post" action="<?php $PHP_SELF;?>">
Name:<input type="text" size="10" maxlength="10" name="name"><br />
<input type="submit" value="submit" name="submit">
</form>
<?
}
?>

Btw, javascript is no way of securing a website.

If its for a "members area" then simply make the form direct to members.php, get the members.php to read the POST variable, check it against your MySQL database, or if you going simple compare it with a stored var.



$pass = $_POST["pass"];
if($pass == "enter"){
echo "Welcome to Members Area!";
//Insert Members Area Stuff
}Else{
echo "Sorry you do not have access.. redirecting";
}

Etc..

Camaro'
06-06-2010, 01:45 AM
Can you still do this if you cant edit the file that's receiving the post information?

Like I want to post a thread, after a user fills out the form and hits submit. Not on vBulletin (like SRL does it with members apps)

rogeruk
06-06-2010, 08:35 PM
Can you still do this if you cant edit the file that's receiving the post information?

Like I want to post a thread, after a user fills out the form and hits submit. Not on vBulletin (like SRL does it with members apps)

Was that in relation to my post?

If so, dont really get what you mean

Frement
06-06-2010, 08:42 PM
$pass = $_POST["pass"];
if($pass == "enter"){
echo "Welcome to Members Area!";
//Insert Members Area Stuff
}Else{
echo "Sorry you do not have access.. redirecting";
}

Etc..

Bad example.

Heres yours a little modified:

$pass = md5(htmlspecialchars($_POST["pass"]));
if ($pass == "e2a7106f1cc8bb1e1318df70aa0a3540") {
echo "Welcome to Members Area!";
//Insert Members Area Stuff
} else {
header("Location: error.html");
}

You can also use functions like strip_tags() etc.

rogeruk
06-13-2010, 03:52 PM
Bad example.

Heres yours a little modified:

$pass = md5(htmlspecialchars($_POST["pass"]));
if ($pass == "e2a7106f1cc8bb1e1318df70aa0a3540") {
echo "Welcome to Members Area!";
//Insert Members Area Stuff
} else {
header("Location: error.html");
}

You can also use functions like strip_tags() etc.

How was that a bad example?.

You cant view the PHP, and even if you could your weak MD5 hash password is "enter".

It was a simple example to a simple question, you should NEVER have passwords in the php file, it should always come from a MySQL database or better.

Theres no need in confusing him about strip tags

nielsie95
06-13-2010, 04:50 PM
Bad example.

Heres yours a little modified:

$pass = md5(htmlspecialchars($_POST["pass"]));
if ($pass == "e2a7106f1cc8bb1e1318df70aa0a3540") {
echo "Welcome to Members Area!";
//Insert Members Area Stuff
} else {
header("Location: error.html");
}

You can also use functions like strip_tags() etc.

You shouldn't use htmlspecialchars or htmlentities or strip_tags or things like that for passwords, as you don't print them anyway. Only if you are going to use them in a SQL query you might want to escape them.