Validating 'required' form page data for save to database, Saving by php code file after succesful validation. Success message on |
Validating 'required' form page data for save to database, Saving by php code file after succesful validation. Success message on |
Freddz |
Jan 7 2019, 08:34 PM
Post
#1
|
Novice Group: Members Posts: 25 Joined: 7-January 19 Member No.: 26,791 |
Hello,
I have a form page where I check the mandatory inputs client-sided by the attribute 'required' (when clicking send button). When all required inputs are done the send button click... 1.) should call a php file 'dbinsert.php' which just contains the save process of the form data to a database. 2.) But the success message should be shown on the SAME page, on top of the form page. How can I implement this process under those 2 conditions? I suppose that the send button's 'action' attrbute should be empty and the php file has to be called via Ajax (within a Javascript function?) !? But unfortunately I fail in implementing THIS specific configuration. Could you help me, please? If so, please specify in your answer all necessary code lines like the form header, the submit button and the Javascript function that executes the Ajax call (and also fires the success message, I suppose)? Thank you so much! The following constellation does not work: * <FORM NAME="Betrugseingabe" ACTION="../cgi-bin/DBinsert.php" METHOD=POST> * <INPUT TYPE="submit" NAME="Absenden" VALUE="Absenden" ID="Schaltflaeche1" formtarget="_self"> |
Freddz |
Jan 21 2019, 06:52 AM
Post
#2
|
Novice Group: Members Posts: 25 Joined: 7-January 19 Member No.: 26,791 |
Yes, I know that I have to edit the generated file afterwards to e.g. realise iFrame support. However, it is nerving to do that any time you modify this page.
That's why I am prefering a solution that forces manual modifications as less as possible. So that's why I am currently concentrating on solution 4. Unfortunately this doesn't work yet. What I did: I added an .htaccess file in the html folder with the line: "AddType application/x-httpd-php .html .htm" and set in the /etc/apache2/apache2.conf file the AllowOverride option from 'none' to 'all': <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> But my test page of the isset function is still not working. What I couldn't find yet: 1) A proof command if the above apache config file really is the right one. Cannot find an apache command for asking its config file to be totally sure. 2) Cannot find an apache proof command for asking its current override setting. Points 1 and 2 for making sure that override is really working... 3) Maybe there is still a mistake at my page file!?... Therefore I copied it below to this message for you. I would appreciate it if you could have a quick look... Thank you so much for your continuous help !!! Here is the isset page code: ++++++++++++++++++++++++++++++++++++++++++++++++ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> </HEAD> <BODY NOF="(MB=(DefaultMasterBorder, 150, 51, 66, 0), L=(KontaktLayout, 849, 452))"> <DIV ID="LayoutLYR"><LAYER ID="LayoutLYR" TOP=0 LEFT=0 VISIBILITY=INHERIT WIDTH=915 HEIGHT=653 Z-INDEX=1><DIV ID="Text39LYR" CLASS="TextObject"><LAYER ID="Text39LYR" VISIBILITY=INHERIT TOP=190 LEFT=81 WIDTH=801 HEIGHT=38 Z-INDEX=1> </LAYER></DIV><DIV ID="Tabelle4LYR" STYLE="background-color: rgb(217,217,217);"><LAYER ID="Tabelle4LYR" VISIBILITY=INHERIT TOP=249 LEFT=104 WIDTH=746 HEIGHT=272 Z-INDEX=2 bgcolor="#D9D9D9"> <FORM NAME="Tabelle4FORMULAR" METHOD=POST> <?php if(isset($_POST['Absenden'])) { // put form handler script here echo "Form was submitted (field data saved successfully)!..."; } else { echo "Form was not submitted."; } ?> <TABLE ID="Tabelle4" BORDER=0 BGCOLOR="#D9D9D9" CELLSPACING=3 CELLPADDING=1 WIDTH="100%"> <TR> <TD> <P> </P> </TD> <TD WIDTH=136> <P><B>Thema:</B></P> </TD> <TD WIDTH=253> <P> <SELECT ID="Auswahlfeld1" NAME="Auswahlfeld1" required> <OPTION VALUE="" SELECTED>/ Thema wählen /</OPTION> <OPTION VALUE="1">Option 1</OPTION> <OPTION VALUE="2">Option 2</OPTION> <OPTION VALUE="3">Option 3</OPTION> <OPTION VALUE="4">Option 4</OPTION> <OPTION VALUE="5">Option 5</OPTION> </SELECT> </P> </TD> <TD WIDTH=299> </TR> <TR> <TD> <P> </P> </TD> <TD> <P> </P> </TD> <TD WIDTH=253> <P STYLE="text-align: center;"><INPUT TYPE=SUBMIT NAME="Absenden" VALUE="Abschicken" ID="Schaltflaeche1"></P> </TD> <TD> <P> </P> </TD> <TD> <P> </P> </TD> </TR> </TABLE> </FORM> </BODY> </HTML> +++++++++++++++++++++++++++++++++++++++++++++++ This post has been edited by Freddz: Jan 21 2019, 07:05 AM |
Christian J |
Jan 21 2019, 11:09 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,684 Joined: 10-August 06 Member No.: 7 |
I added an .htaccess file in the html folder with the line: "AddType application/x-httpd-php .html .htm" Without the quotes I hope? In any case, the exact directive can be very different depending on how Apache is configured. Asking the web host should be the easiest approach. QUOTE and set in the /etc/apache2/apache2.conf file Are you running your own server? AFAIK you sually don't have access to that file on shared hosts? QUOTE Afterwards I tested your last suggestion, Christian, to rename the page file from .html to .php for testing. And SURPRISE: This works!! So it seems as if the page code is okay but Apache is still not configured correctly (of course I didn't forget to restart it)!... Good! I wouldn't say it's configured incorrectly though, it's just a matter of preference. If you want you can simply keep using the .php extension, that's what most sites do (including this forum). |
Lo-Fi Version | Time is now: 10th June 2024 - 06:37 AM |