9 Replies - 1628 Views - Last Post: 21 August 2013 - 11:21 PM

#1 NoWayIn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-December 09

Set textbox value to a variable from PHP

Posted 21 August 2013 - 10:43 PM

So for my PHP code I have this :

<?php
$title = "";
$username = "";
function get_page_title($url){
  if( !($data = file_get_contents($url)) ) return false;
  if( preg_match("#<title>(.+)<\/title>#iU", $data, $t))  {
    return trim($t[1]);
    } else {
    return false;
    }
  }
$title =  get_page_title("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$username = explode('@',$title);
?>


Then, below that I have a form :

<form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<label for="email">Username:</label>
                <input  value=<?php ?> type="text" readonly="true" name="email" id="email"/><br><br>
                <label for="newPass"/>Password : </label>
                <input type="text" name="newPass" id="newPass"/><i>This is going to be your new password</i>
				<br><br><br>
<input class="btn" type="submit" name="submit"  class="submit" value="Update Password"/>
              
        
    </form>


How do I set the value of $username to the textbox named "email"?
I tried doing
<input  value=<?php echo $username[0];?> type="text" readonly="true" name="email" id="email"/>

But it doesn't return the correct value.

Is This A Good Question/Topic? 0
  • +

Replies To: Set textbox value to a variable from PHP

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,231
  • Joined: 08-June 10

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 10:52 PM

Quote

But it doesn't return the correct value.

what does it display then?
Was This Post Helpful? 0
  • +
  • -

#3 NoWayIn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-December 09

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 10:54 PM

In the textbox, it displays "Timed"

This post has been edited by Dormilich: 21 August 2013 - 10:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,231
  • Joined: 08-June 10

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 10:57 PM

any idea where that comes from?

besides that, check every dependent variable (esp. $url & $title) if they contain the values you assume.
Was This Post Helpful? 0
  • +
  • -

#5 NoWayIn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-December 09

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:01 PM

I didn't specify any variable with the strong "Timed" so I have no idea where that comes from.
I tested the script in a new file called "test.php" and it works :

<html>
<title>test@amail.tv - index</title>
</html>

<?php
$title = "";
$username = "";
function get_page_title($url){
  if( !($data = file_get_contents($url)) ) return false;
  if( preg_match("#<title>(.+)<\/title>#iU", $data, $t))  {
    return trim($t[1]);
    } else {
    return false;
    }
  }
//echo get_page_title("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$title =  get_page_title("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$username = explode('@',$title);
echo $username[0];
?>
<html>
<form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<label for="email">Username:</label>
                <input  value=<?php echo $username[0];?> type="text" readonly="true" name="email" id="email"/><br><br> 
                <label for="newPass"/>Password : </label>
                <input type="text" name="newPass" id="newPass"/><i>This is going to be your new password</i>
				<br><br><br>
<input class="btn" type="submit" name="submit"  class="submit" value="Update Password"/>
              
        
    </form>
	
	</html>


However, if I use that exact code in my own script, it just show "Timed" in the textbox

This post has been edited by Dormilich: 21 August 2013 - 11:04 PM

Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,231
  • Joined: 08-June 10

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:04 PM

Quote

I tested the script in a new file called "test.php" and it works :

then its probably a problem is the source text.

again: check every dependent variable (esp. $url & $title) if they contain the values you assume.
Was This Post Helpful? 0
  • +
  • -

#7 NoWayIn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-December 09

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:09 PM

Well here is the whole file if you would like to take a look at it :

<div id="primary_header">
  <h1><?php print $this->translate('Change Password')?></h1>
	<div id="back_button">
		<a href="#">
			<span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
		</a>
	</div>
</div>

<div id="back_button" class="savecontact">
<a href="#">
<span>
<?php print $this->translate('Save Password')?>
</span>
</a>
</div>


<div id="primary_content">
  <div id="primary_content_inner">
 <?php
    $error = false;
    $sent = false;

    if(isset($_POST['submit'])) {
        if(empty($_POST['email']) || empty($_POST['newPass'])) {
            $error = true;
        } 
        else {

include("xmlapi.php"); 
$ip = 'IP';
$root_pass = 'PASS';
$account = "LOGIN";


$email = $_POST['email'];
$newpass = $_POST['newPass'];


$xmlapi = new xmlapi($ip); 
$xmlapi->password_auth("amail",$root_pass); 
$account = "LOGIN"; 
$xmlapi->api2_query($account, "Email", "passwdpop", array( 'domain' => "DOMAIN.COM", 'email' => "$email", 'password' => "$newpass") );  

            if($xmlapi) {
			echo '<script type="text/javascript">alert("Your password has been updated. You will now logout. You can login again with the new password.")</script>';
			header('Location: http://domain.com/logout');
                
            }
       }
  }
?>
<?php if($error == true){ ?>
<p class="error">Error</p>
<?php } if($sent == true) { ?>
<p class="sent">Password Updated!</p>
<?php } ?>  

<?php
$pagename = "";
$currentemail = "";
function get_page_title($url){
  if( !($data = file_get_contents($url)) ) return false;
  if( preg_match("#<title>(.+)<\/title>#iU", $data, $t))  {
    return trim($t[1]);
    } else {
    return false;
    }
  }
//echo get_page_title("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$pagename =  get_page_title("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$currentemail = explode('@',$pagename);
?>

    <form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
				<label for="email">Username:</label>
                <input  value=<?php echo $currentemail[0];?> type="text" readonly="true" name="email" id="email"/><br><br> 
                <label for="newPass"/>Password : </label>
                <input type="text" name="newPass" id="newPass"/><i>This is going to be your new password</i>
				<br><br><br>
<input class="btn" type="submit" name="submit"  class="submit" value="Update Password"/>
    </form>


</div>
</div>

<script type="text/javascript">
$(function() {

    // bind to the form's submit event and cancel legacy submit 
    $('#settingsForm', "#password").submit(function() {   
	    $("#Flash", "#password").hide();

        $('#back_button a', '#password').fadeTo("slow", 0.5);
        $('#back_button a', '#password').addClass("disabled");
        $('#back_button a', '#password').removeClass("enabled");

        if(!$("#currentPassword").attr('value')) {
			alert('<?php print addslashes($this->translate('Please specify the current password'))?>');
            $('#back_button a', '#password').fadeTo("slow", 1);
            $('#back_button a', '#password').addClass("enabled");
            $('#back_button a', '#password').removeClass("disabled");
			$("#currentPassword").focus();
		}

		else if(!$("#newPassword").attr('value')) {
			alert('<?php print addslashes($this->translate('Please specify the new password'))?>');
            $('#back_button a', '#password').fadeTo("slow", 1);
            $('#back_button a', '#password').addClass("enabled");
            $('#back_button a', '#password').removeClass("disabled");
			$("#newPassword").focus();
		}

		//else if($("#newPassword").attr('value').length<6) {
		//	alert('<?php //print addslashes($this->translate('Password is too short. Must more than 6 characters/digits.'))?>');
		//	$("#newPassword").focus();
		//}

		else if(!$("#newPassword2").attr('value')) {
			alert('<?php print addslashes($this->translate('Please type the password confirmation'))?>');
            $('#back_button a', '#password').fadeTo("slow", 1);
            $('#back_button a', '#password').addClass("enabled");
            $('#back_button a', '#password').removeClass("disabled");
			$("#newPassword").focus();
		}

		else if($("#newPassword").attr('value') != $("#newPassword2").attr('value')) {
			alert('<?php print addslashes($this->translate('New passwords do not match, please verify'))?>');
            $('#back_button a', '#password').fadeTo("slow", 1);
            $('#back_button a', '#password').addClass("enabled");
            $('#back_button a', '#password').removeClass("disabled");
			$("#newPassword").focus();
		}
		
		else {		
		$.php($("#settingsForm", '#password').attr("action"),$("#settingsForm", "#password").serializeArray());
		}
        $('#currentPassword').attr('value','');
        $('#newPassword').attr('value','');
        $('#newPassword2').attr('value','');
        $('#back_button a', '#password').fadeTo("slow", 1);
        $('#back_button a', '#password').addClass("enabled");
        $('#back_button a', '#password').removeClass("disabled");
		return false;
    });

    $('#back_button a', '#password').bind("click", function() { return $('#settingsForm', "#password").submit()})

	$('.stronglastword').each( function() { $(this).stronglastword() });

});
</script>


I don't know how to edit the post so hopefully this gets posted below it.
That is the whole script.
I'm sure I did not use the same variable and I did not set any variable to "timed"

This post has been edited by Dormilich: 21 August 2013 - 11:10 PM

Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,231
  • Joined: 08-June 10

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:09 PM

again: check every dependent variable (esp. $url & $title) if they contain the values you assume.
Was This Post Helpful? 0
  • +
  • -

#9 NoWayIn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 06-December 09

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:16 PM

No matter what I do, the textbox continues to display "Timed"
I'm not sure what to do next :\
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,231
  • Joined: 08-June 10

Re: Set textbox value to a variable from PHP

Posted 21 August 2013 - 11:21 PM

that what I am telling you the whole time: check every dependent variable (esp. $url & $title) if they contain the values you assume.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1