Welcome! Log In Create A New Profile

Advanced

Saving Type in User Information

Posted by 77928490 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Saving Type in User Information
April 23, 2013 10:24PM
Hi All,

It looks like we are all frantically working.

Quick question I hope.

When we create an input type 'text', we can store the users information in the texb box by using the following:-

Language: HTML
$usertext="Enter Text Here";   <input type=';text'; name=';example'; value="<?php print $usertext; ?>"

My problem is, whenever I click on the 'submit' button, I can capture the user information correctly, but the default $usertext value is reprinted.

My question is how can we ensure the user typed in information is displayed instead of the default value?

Thanks guys.

Cheers
Re: Saving Type in User Information
April 24, 2013 08:45AM
Hey 70363137

You need to correct your $usertext - or at least when it is set.
You can do it like this: -
<html>
<head>
<title>A FORM</title>
<?php
if (isset($_POST['Submit']))
{
$usertext = $_POST['example'];
}
else
{
$usertext="Enter Text Here";
}
?>

</head>
<body>

<form name="form1" method="post" action="">
<input type='text' name='example' value="<?php print $usertext; ?>"
<input type = "Submit" name = "Submit" value = "Submit">
<br/>

</form>
</body>
</html>

If you click on "Submit", the variable is set to whatever was entered and gets re-displayed in the text box, if the form was NOT submitted then the default text gets assigned to the variable and entered in the text box.

Glen
Re: Saving Type in User Information
April 24, 2013 08:46AM
Just remember that the variable is set in the "HEAD" part of the page.

Glen
Re: Saving Type in User Information
April 24, 2013 08:52AM
Just cleaned up a bit to look better: -
<form name='form1' method='post' action=''>
<input type='text' name='example' value="<?php print $usertext; ?>"
<br/>
<input type = 'submit' name = 'submit' value = 'Submit'>
<br/>

Glen
Re: Saving Type in User Information
April 24, 2013 11:51AM
Hi 70363137

Thanks a ton. Great help.

I noticed you split your example between a HTML section and a PHP section. The reason is I followed the forum example and put all the HTML bits and pieces into variables in another php file which gets included. So I print a table in the main php file calling the HTML code from another file.

Do you think that is ok for this assignment?

Thanks again.
Re: Saving Type in User Information
April 25, 2013 08:26AM
One of the nice things I like about PHP is that you can achieve the end result by using many different ways. This allows me to be challenged a bit - if I am getting stuck with a particular route I have the option of following another.

Just be sure to follow the instructions for the final project.

Glen
Sorry, only registered users may post in this forum.

Click here to login