Send Output of PHP Script to Textarea

Greetings guys and gals :slight_smile:

I’m quite new to PHP and need a little help.

I have a form that when an appropriate ID is entered, then grabs some info from a webpage and displays it. What I need is for that info to be displayed in a textarea below the form.

The form:

[code]

Enter the album ID:




<div id="output">

    <!-- I need the output of the PHP script to display in the textarea below: -->

    <textarea></textarea>
</div>[/code]

The PHP code:
[php]require_once(‘simple_html_dom.php’);

if (empty($_POST[“album_id”])){
print “Whoops, you left the field empty!”;
}
else
{
// Create DOM from URL
$html = file_get_html(‘http://vgmdb.net/album/’.$_POST[“album_id”]);
$url = (‘http://vgmdb.net’);

// Grab the tracklist
foreach($html->find('div#tracklist') as $element)
echo $element;

} [/php]

I tried this:

<textarea><?php echo $element; ?></textarea>

… but it obviously loads this on the ‘test.php’ page. Is it possible to dump the output of the PHP script straight into the text area below the form?

I tried this <?php echo $element; ?>

Actually, that is correct! I’m guessing you haven’t established a value (string) for $element.

Add this above your form code…

<php $element=“This is a test”; ?>

Run and your textarea should contain This is a test.

You must either pass information to your form html file or use an inline php block to populate the string. What information you add to $element is your responsibility. An empty string will produce and empty textarea.

I managed to figure it out in the end:

[code]jQuery(document).ready(function() {

jQuery("#form2").hide();

jQuery("#myform").validate({
    debug: false,
    rules: {
        name: "required"
    },
    submitHandler: function(form) {

        // show alert if field is empty
        if (jQuery("#name").val() === '') {

            jAlert('You left the field empty!', 'Alert!');

        }

        else {

            // do stuff
        }
    }

});

});[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service