0

I am very new to HTML and PHP and have spent hours trying to find the right questions to ask. I would like to create a simple webform on a page and add a button that will generate text (on the same page) based on the variables answered in the webform. I don't need to/want to capture the data from the form. I do not want to show the output in a table format. If possible, I would like the output to be editable and have a copy button. The user would answer the questions they want to, then see the summary of their answers. Any questions they skipped would not show up in the summary. In an ideal situation, they would also be able to edit the compiled text before copying it.

Example:

Question 1 (required)
Question 2 (optional)
Question 3 (optional)

[Generate]

(On webpage, print:) "Hello (Q1 answer). Based on your blah blah, we think your idea to (Q2 answer) is great!"

This is do-able, right? I feel like it is such a simple thing to do that no one talks about how to do it. I understand how to create forms and input fields, but I'm not sure how to make the generate button that will compile the answers from the questions into a paragraph on the page. Any syntax examples would be so, so helpful.

Thank you!!

1
  • I'm getting closer! I learned I can do the "generate" portion with onclick but haven't figured out how to print more than one variable together yet.
    – Carter
    Commented Dec 24, 2021 at 0:53

2 Answers 2

0

So all you want to do is have a person type information in a few fields, then you display all that information in a sentence structure? You don't need PHP for that. JavaScript will do the job.

The following page will set up a JavaScript form on your page and how to get the information back into your page: https://www.javascripttutorial.net/javascript-dom/javascript-form/

I think it's going to be hard going if you have never done JavaScript before, though.

1
  • Yes, I think so? But one based on their answers. Thank you for the link, I'll take a look.
    – Carter
    Commented Dec 23, 2021 at 22:26
0

If you use a <form method="POST action="#">, you can add this follow code in your PHP file :

<?php 
if ( !empty($_POST['q1']) ) {
  echo 'Hello ' . $_POST['q1'] . '.<br>';
}
if ( !empty($_POST['q2']) ) {
  echo "Based on your blah blah, we think your idea to " . $_POST['q2'] . " is great!";
}
?>

<form action="#" method="POST">
    <label>
        Your name :
        <input type="text" name="q1">
    </label>
    <label>
        Your idea :
        <input type="text" name="q2">
    </label>
</form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.