php - Form (htm & ajax) not registering -
My AJAX code is rejecting a post that is full of an html form. Instead of the actual content, my txt file is just filling with the word 'first name last name age' where am I going?
(I have a submit button, when pressed, will hide the device and one can open another - I do not know it is important information)
This is HTML:
General introduction & lt; Form action = "action_page.php" & gt; & Lt; Fieldset & gt; & Lt; Legend & gt; Personal info: & lt; / Legend & gt; First name: & lt; Br> & Lt; Input type = "text" name = "firstname" & gt; & Lt; Br> Last name: & lt; Br> & Lt; Input type = "text" name = "last name" & gt; & Lt; Br> Age (in the number, for example, "47", "forty-seven"): & lt; Br> & Lt; Input type = "text" name = "age" & gt; & Lt; Br> & Lt; Br> & Lt; / Fieldset & gt; & Lt; / Form & gt; & Lt; P & gt; & Lt; Button Type = Button ID = 'Submit' & gt; Submit my information & lt; / Button & gt; & Lt; / P & gt; This is the code in my action_page.php
$ firstname = $ _POST ['first name']; $ Lastname = $ _POST ['last name']; $ Age = $ _POST ['age']; $ Out; $ Result = file_put_contents ("log.txt", PHP_EOL. "First name". $ Firstname. "Lastname". $ Lastname. "Age". $ Age, FILE_APPEND); If ($ Result! == FALSE) {$ out = ["message" => "Success!", "Status" = & gt; 200]; } And {$ out = ["Message" = & gt; "Error saving file", "status" = & gt; 500]; } Echo json_encode ($ out); Go out();
This does not look like an Ajax, but you should be able to
& lt; Form action = "action_page.php" & gt; Resolve your problem by changing to
& lt; Form action = "action_page.php" method = "post" & gt;
Comments
Post a Comment