Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data from text area into an array using split()

Status
Not open for further replies.

Chucklez

Programmer
Jul 25, 2002
104
US
Im a nOObie at this stuff, so please forgive me if this is a stupid question.

On my html form I have a text area set up using the following tag:

<textarea name=report wrap=virtual onfocus="select()" rows=20 cols=109></textarea>

The user enters tab delimited information into this textbox, where a series of functions are performed on it. What I am having problems doing is taking this information, splitting it and putting it into an array, then displaying the information.

Here is where I declare my array, and gather the info from the textarea and split it into the array:

$TEXT = isset($_POST['report']) ? trim($_POST['report']) : "";
$_SESSION['report'] = $TEXT;

$INFO=array($NAME, $ADDY, $CITY, $STATE);
$INFO=split("\t",$TEXT);

Here I am displaying just the name (I put the echo $text command to see if I was even bringing my info in right):

<textarea name=report wrap=virtual onfocus="select()" rows=20 cols=109>
<?
echo $NAME;
echo $INFO;
echo $TEXT;
?>
</textarea>

The only output I receive here is "array" which I am assuming is coming from the $INFO variable.

What am I doing wrong here, and how do I correct it? I assume the split() is working right, but I can be certain as it appears I am not gathering the info from the textarea correctly. So is this a session problem?

Thanks in advance.
 
Never assume anything, always check.

First at the start of the script, make sure that what the script is seeing from the form input is what you expect by adding
Code:
echo '<pre>';print_r($_POST);echo '</pre>';

Next you have the two lines:
Code:
$INFO=array($NAME, $ADDY, $CITY, $STATE);
$INFO=split("\t",$TEXT);
What do you think or want these lines to do?

The first line creates an array contain the values of $NAME, $ADDY, $CITY, and $STATE (all null at this time). The next line overides that and creates an array containing the split information from the variable $TEXT.

WHen you want to see what's in an array, use either var_dump() or print_r(), not echo.

Ken
 
OK, I tried what you suggested, and I see now I obviously am not passing that data. Below is my code.

Code:
<?
$do = isset($_REQUEST['do']) ? trim($_REQUEST['do']) : "";
$id = isset($_GET['id']) ? trim($_GET['id']) : "";
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$self = $_SERVER['PHP_SELF'];
$admin_password = "admin";

session_start();
switch ($do) {
case "":
?>

<style type="text/css">
a:link {color: #CC9900}
a:visited {color: #CC9900}
a:hover {color: #CC9900}
a:active {color: #CC9900}
</style>

<html>
   <body text="#CC9900" bgcolor="#000000" link="#CC9900" vlink="#CC9900" alink="#CC9900">
   <form method="post" action="<?=$self?>">
      <center>
         <h1 style="font-family:coronet;font-size:300%"> The Wassai </h1>
         <img src="[URL unfurl="true"]http://wassai.coconia.net/logo.JPEG">[/URL]
      </center>
      <div align=center>
         <form name=Name Tracker>
            <center>
               Name Tracker
            </center>
            <font size="1">
            <br>
            <textarea name="report" wrap="virtual" onfocus="select()" rows="20" cols="109">
        From Member screen Paste the entire list into this text box, then click scan
            </textarea>
            <BR>
            <BR>
            <input type="button" value="scan" onclick="window.location='<?="$self?do=scan&page=$page"?>'">
            <BR>
            <BR>
         </form>
      </div>
   </body>
</html>

<?
break;

//*******************************BEGIN SCAN FUNCTIONS****************************************
case "scan":

$TEXT = isset($_POST['report.value']) ? trim($_POST['report']) : "";
$_SESSION['report'] = $TEXT;

$INFO=split("\t",$TEXT);
?>

<style type="text/css">
a:link {color: #CC9900}
a:visited {color: #CC9900}
a:hover {color: #CC9900}
a:active {color: #CC9900}
</style>

<html>
   <body text="#CC9900" bgcolor="#000000" link="#CC9900" vlink="#CC9900" alink="#CC9900">
   <form method="post" action="<?=$self?>">
      <center>
         <h1 style="font-family:coronet;font-size:300%"> The Wassai </h1>
         <img src="[URL unfurl="true"]http://wassai.coconia.net/logo.JPEG">[/URL]
      </center>
      <div align=center>
         <form name=Name Tracker>
            <center>
               Name Tracker
            </center>
            <font size="1">
            <br>
            <textarea name="report" wrap="virtual" onfocus="select()" rows="20" cols="109">
               <?
                  echo $NAME;
                  echo $TEXT;
               ?>
            </textarea>
            <BR>
            <BR>
            <BR>
            <BR>
         </form>
      </div>
   </body>
</html>
<?
}
?>

I am still getting nothing coming from the first form <textarea>. I see this because my array appears to contain nothing.

I want to split up the information that is entered into my text box into an array, then sort them out by state, and place them in that order.

Can you atleast point me in the right direction?
 
This piece of code is confusing.
Code:
$TEXT = isset($_POST['report[b][red].value[/red][/b]']) ? trim($_POST['report']) : "";
Looks to me like there are remnants of VB or something. I think you should get rid of that .value there. If not, your condition will always evaluate as false and $TEXT will be empty. Also, I did not found anywhere in the code where $NAME would be defined, so you're putting two blank variables in the textarea and coming back with nothing.
 
I apologize. the '.value' was something i added just trying to find a possible solution. Basically, it was just guessing blindly.

The name is a remnant of the array I attempted to declare (see earlier post).

But still, shouldnt the:
Code:
$TEXT = isset($_POST['report']); //? trim($_POST['report']) : "";

[color=red]echo $TEXT;[/color]
produce some type of result?
Shouldnt it atleast display on the top of the page a copy of the text that is in the <textarea> from the previous section?

Thats what is confusing me at the moment, I dont appear to be passing any information.
 
This code should TRUE or FALSE in $TEXT. As I can see, the ternary if is not used, because you commented it out and you set the $TEXT to the value of the isset function ran on $_POST['report']. If report is set, $TEXT should be TRUE, if not $TEXT should be FALSE.
 
So then how do I pass the info that is in my textarea to a session variable?

I apologize, but I didnt quite understand what you were talking about in your previous post.
 
What is wrong with simple:
Code:
if (isset($_POST['report'])) 
{
  $_SESSION['report'] = $_POST['report'];
}
 
I must be doing something wrong, I did as you said, and still nothing.
 
Well, from the code you supplied it is not obvious, so I will ask:

1. Where is this session information used and how can you see it is not working?
2. Are you sure that $_POST array has the information you are looking for?

Inspecting your code again, I noticed that you are not even submitting the form in the first pass. Using javascript to redirect to another page on a button command will not submit the form. It will simply load another page. If you want to submit, you should add a submit button. Try changing the first pass form to look like this:
Code:
   <form method="post" action="<?=$self . "?do=scan&page=" . $page ?>">
   ...
     <input type="submit" value="scan" />
   ...
 
Thank you. I finally got the info passed (for lack of a better word) that I wanted. I knew it was a stupid error.

I set up another php page several months back, and that worked no problem. Guess the sun shines on a dogs but every once in awhile, eh?

Now I just need to break up the info I am pasting, and put it into an array.
 
1 more question, and this concerns arrays. Say I have a tab delimited peice of information as follows

steve\t42marion drive\tAnywhere\tIllinois
Herman\t1313 Mockingbird Ln\tmunsterville\tohio
danny\t41 RR41\tpleasantville\tkentucky
ricki\t1East Third st\tthatonetown\tFlorida

The user will cut and paste this information into the <textarea> that I had created above. How do I input this information into an array? I have been trying to use this, but it isnt giving me the output I desire:
Code:
$INFO=explode("\t",$REPORT);
All this is doing is putting all the information into the array, and is not seperating it by the tab.

I want to access this information by its name such as:

Code:
$INFO=array($NAME, $ADDY, $CITY, $STATE);
Is it possible to do that? And if so, how?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top