SRL Archive - Web Development

field value?


Illkillutill

2010-06-04 05:20:23

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?

Gu3st...

2010-06-04 05:22:49

You have to set "action" and "method". :)

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

Illkillutill

2010-06-04 05:29:05

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

2010-06-04 05:34:32

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

Illkillutill

2010-06-04 05:37:49

still keeps coming up with an undefined :(

Frement

2010-06-04 05:48:03

From: Illkillutill
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

2010-06-04 14:19:27

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

2010-06-05 02:19:21

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

2010-06-05 03:06:17

<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

2010-06-05 17:51:54

[php]<?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>
<?
}
?> [/php]

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.

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

Camaro'

2010-06-05 21:45:58

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

2010-06-06 16:35:52

[QUOTE=Camaro';715061]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

2010-06-06 16:42:59

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


Bad example.

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

You can also use functions like strip_tags() etc.

rogeruk

2010-06-13 11:52:08

From: Frement
Bad example.

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

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

2010-06-13 12:50:00

From: Frement
Bad example.

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

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.