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"> |
CharlesEF |
Jan 15 2019, 03:53 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,984 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I forgot to say that you didn't post enough 'DBinsert' code for me to tell if you will get a response back from the ajax call. Also, in the 'DBinsert.php' file you should check to make sure every value needed is supplied in the $_POST array before doing the database insert.
|
Freddz |
Jan 18 2019, 09:13 AM
Post
#3
|
Novice Group: Members Posts: 25 Joined: 7-January 19 Member No.: 26,791 |
I forgot to say that you didn't post enough 'DBinsert' code for me to tell if you will get a response back from the ajax call. Also, in the 'DBinsert.php' file you should check to make sure every value needed is supplied in the $_POST array before doing the database insert. Thank you very much, Charles. Your code is working fine! However, I don't understand the function onsubmit that good. But I will double check it soon by reading about it. I just havn't much time right now, unfortunately. Additional form elements I would add just by additional code lines of "formData.append(....", right? I tried that and it worked fine... So thank you very much again!!! I will see which solution is better to integrate into NOF now, sol. 3 or 4... |
CharlesEF |
Jan 18 2019, 02:37 PM
Post
#4
|
Programming Fanatic Group: Members Posts: 1,984 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Additional form elements I would add just by additional code lines of "formData.append(....", right? Yes, that is correct. As for security, since you are using 'mysqli' you should use parameterized queries. That will help guard against malicious sql code. As for NOF, I would never design a website based on the limitations of software. But I don't use any program to write any of my code. |
Lo-Fi Version | Time is now: 26th September 2024 - 08:33 PM |