0

A form loads and user enters their data. Form is submitted, with unrelated errors and the form page needs to be reloaded. I want to re-refill (re-populate) the Textarea with the user's prior comment data.

I figured out how to repopulate fields of type=text and type=checkbox. I don't see any way to pass data to the form to put into the textarea. Text & checkbox have value="" and "checked" which work.

Solution: the area between the textarea attributes and textarea close tag, is text that loads into the textarea as an initial value.

Here's the textarea options on 3wschools: https://www.w3schools.com/tags/tag_textarea.asp

I made a snippet. I can fill the address text field using value="Sunshine Lane". What can be used to pass to Textarea to fill it?

<form action="Online/DonateOnline.php" method="post" target="_self">

<label for "dcomments">Comments</label><span>
<textarea name="dcomments" id="dcomments" cols="100" rows="3"></textarea></span>

 <br>
 <br>
<!-- this text field works -->
<label for "address1">Address1*</label><span>
<input value="Sunshine Land"
name="address1" id="address1" type="address1" size="80" ></span>
 <br>
 <br>

<span>
<input type="submit" name="SubmitDForm" id="SubmitDForm"  value="Continue" >
</span>

</form>

---------------------------------

The only thing I see so far is to use ajax. But I don't know ajax & don't even know if it's set up on this system. Re-populating radio buttons and selection option in a form

curls
  • 382
  • 1
  • 3
  • 16
  • you have 2 questions here... how to repopulate the textarea and how to load its text into a mailto: form, or did I miss understand? – Guy Louzon Sep 16 '18 at 17:59
  • I'm not asking anything about emailing. I'll change that example so it doesn't confuse. I'm asking only how to repopulate :). (Changes made.) – curls Sep 16 '18 at 18:00
  • 1
    I gave an answer, hope it helps – Guy Louzon Sep 16 '18 at 18:11

1 Answers1

1

Regarding the textarea to be repopulated, assuming that the snippet from the code is the php file,

then a tiny php addition, like this:

    <?php isset($_POST['dcomments']) ? $dc = $_POST['dcomments'] : $dc = ''; ?>
    <form action="Online/DonateOnline.php" method="post" target="_self"> 
<label for "dcomments">Comments</label><span> 
<textarea name="dcomments" id="dcomments" cols="100" rows="3"><?php echo $dc; ?></textarea></span>
 <!-- this text field works --> <label for "demail">Email*</label>
<span> <input value="something@test.org" name="demail" id="demail" type="email" size="80" ></span> 
    <br>    <br> <span> <input type="submit" name="SubmitDForm" id="SubmitDForm" value="Continue" > 
</span> </form>
Guy Louzon
  • 1,175
  • 9
  • 19
  • That's it! SOOO simple. It's just putting the info into the area between the . I can't believe I didn't think of trying that with some many hours spent on this, lol. – curls Sep 16 '18 at 18:14
  • 1
    know the feeling too well myself :) – Guy Louzon Sep 16 '18 at 18:15
  • In your code is the queston mark ?, between the isset and setting $dc, does that question mark translate as "if (isset) then (set value)". Is the ? a shorter way of doing if then? If it is, it'd come in handy! – curls Sep 16 '18 at 18:17
  • What's the : $dc = '' accomplish? What's the :? I just noticed them, and they look like a handy short cut too? An else $dc is set to blank? So the : is an Else? – curls Sep 16 '18 at 18:24
  • 1
    yes $dc is to be set to blank, if no post info arrived, to prevent errors – Guy Louzon Sep 16 '18 at 18:38