简体   繁体   中英

Reading in Data from HTML Javascript form

I am creating a website backed by a database. I have created my forms that collect the information but now i need to read in the input from the form when user clicks submit and process it for mySQL. I am having my form action be a new page but I can't figure out how to read in value from the previous page. My Form code looks like this:

<div data-wrapper-react="true">
        <span class="form-sub-label-container" style="vertical-align:top;">
          <input type="text" id="first_3" name="q3_fullName3[first]" class="form-textbox validate[required]" size="10" value="" data-component="first" />
          <label class="form-sub-label" for="first_3" id="sublabel_first" style="min-height:13px;"> First Name </label>
        </span>

When user hits submit the action for this page is connect.php. I am not sure how to read in the value there. I tried this following command:

document.getElementById("first_3").value; 

This just displays the code on blank html page for connect.php and not read in the values. The data from the forms needs to be processed into different tables if someone can help with that as well that would be great. Thanks

Form handling, in the way you are describing, is something you do server-side. PHP is handled on the server first where PHP tags can be evaluated to HTML, then this is returned to the browser. You would not handle form input from javascript, until after your PHP has done something with it. Here is a refresher: https://www.w3schools.com/php/php_forms.asp

<?php echo $_POST["q3_fullName3[first]"]; ?> <?php echo $_POST["q3_fullName3[first]"]; ?> would output the value into the HTML page allowing you to do something like this:

console.log("<?php echo $_POST["q3_fullName3[first]"]; ?>");

If you view source of the HTML, you will notice the PHP tag is gone and replaced with the form field value.

It sounds like you might want to get a book about PHP + MySQL since interacting with a database is a more advanced topic. I can recommend this one: https://www.amazon.com/Learning-PHP-MySQL-JavaScript-Javascript-ebook/dp/B00QUBHNFI/ref=mt_kindle?_encoding=UTF8&me=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM