PDA

View Full Version : go to a url entered in a certain textbox



motormichael12
11-10-2006, 01:46 AM
Okay i need to make it so that the text area "place" can have a url entered into it, and then after it is entered and submitted it will set $line to go to the url entered.


<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" name="todo">
<input type="hidden" name="ohash" value="<?php echo $hash ?>" />
<pre>
<?php

$data = file ( $file );
$n = 0;

foreach ( $data as $line ) {

echo "<input type='checkbox' name='line[$n]' />";
echo $line ;

$n++;

}

?>
</pre>
<hr />
<input type="text" name="place" size="35" />
<input type="text" name="data" size="35" />
<input type="submit" name="submit" value="Add" />
<input type="submit" name="submit" value="Remove" />
</form>

d-one
11-10-2006, 10:58 AM
Pretty simple:


//After form has been submited
<?Php header("location:".$_POST['place']); ?>

d-one ;)

motormichael12
11-10-2006, 02:23 PM
so do i put that right after the submit button or in the script?

motormichael12
11-10-2006, 02:30 PM
oh no i mean when you click on the text in $line, it goes, not when the page is submitted.

GITs
11-10-2006, 02:57 PM
if that is the case, your in the wrong place, PHP can only do this on the server side, you probably want to use javascript to do this

Insert in the head of the page:


<script language="javascript" type="text/javascript">
function gothere(){
if (document.todo.place.value != ""){
document.location.href=document.todo.place.value;
}
else{
alert("please enter a location!");
}
return false;
}
</script>

Then in the <form> tag, place this somewhere


onSubmit="gothere()"

or do you want the page to reload with the link on the page?

if that is the case, use javascript again...


<script language="javascript" type="text/javascript">
function gothere(){
if (document.todo.place.value != ""){
document.golink.innerHTML="<a href="+document.todo.place.value+">"+document.todo.place.value+"</a>";
}
else{
alert("please enter a location!");
}
return false;
}
</script>

and have this DIV on the page where you want the link to appear...


<div name="todo" id="todo"></div>

hope that this helps somewhat...

motormichael12
11-10-2006, 06:30 PM
well i got part now, but still one problem...

<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST" name="todo">
<input type="hidden" name="ohash" value="<?php echo $hash ?>" />
<pre>
<input type="text" name="place" size="35" />
<input type="text" name="data" size="35" />
<input type="submit" name="submit" value="Add" />
<input type="submit" name="submit" value="Remove" />
<?php

$data = file ( $file );
$n = 0;

foreach ( $data as $line ) {

echo "<input type='checkbox' name='line[$n]' />" ;
echo "<a href=$place>$line</a>" ;

$n++;


}

?>
</pre>

Now is there any way to make it so that even with the fields on top, the data appears above it?

It works right now but makes the fields at the top and I want them switched but the input "place" needs to stay at the top so it can retrieve the field's data in the href...


if that makes any sense.