Jump to content

Recommended Posts

This should be simple, but I am having a hard time figuring this thing out! I have a textarea that I am trying to insert multiple values into.

<form action="music.php" method="post" >
<textarea name="tracks" rows="15" cols="20" id="" tabindex="3" class="" style="width: 300px;"></textarea>
<input type="submit" name="submit_tracks" value="Music">
</form>

 

I am having problems placing the results into an array. What am I doing wrong?

<?php
if($_POST['submit_tracks']) {
//This is the array containing the track information
$tracklisting = $_POST['tracks'];
$tracklisting = array();
//This is the function which will grab anything after the . and return it
function trackname($string){
  $file = $string;
  $i = strrpos($file,'.');
  $trackname = substr($file,$i+1);
  return $trackname;
}

foreach($tracklisting as $track) {
  $trackoutput = trackname($track);
  print "<li>".$trackoutput."</li>";
}
} else print "No Output!";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/169498-solved-input-arrays/
Share on other sites

When you say you are trying to insert multiple values into a textarea, what are you using as a delimiter?  In order to make the posted info into an array, you need to explode at whatever delimiter you are using in the form (like a comma or \n if pressing enter after each one, etc...)

Link to comment
https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894301
Share on other sites

This line

$tracklisting = array();

 

Is overwriting this line

$tracklisting = $_POST['tracks'];

 

I guess you want to loop through the lines enter in the textarea. In which case you'll want to do

This:

$tracks_entered = str_replace(array("\r\n", "\r"), "\n", $_POST['tracks']);
$tracklisting = explode("\n", $tracks_entered);

Link to comment
https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894302
Share on other sites

When you say you are trying to insert multiple values into a textarea, what are you using as a delimiter?  In order to make the posted info into an array, you need to explode at whatever delimiter you are using in the form (like a comma or \n if pressing enter after each one, etc...)

 

After each period

01. Plies - Chef (3:28)

02. Plies Feat. Mario & Hurricane Chris - Headboard (3:33)

03. Plies - On Yac (0:49)

Link to comment
https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894304
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.