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 8 2019, 08:55 AM
Post
#2
|
Novice Group: Members Posts: 25 Joined: 7-January 19 Member No.: 26,791 |
Thank you very much.
But how is the button (<Input Type= ...>) been defined so that the PHP-Script is been executed. JUST this part you unfortunately omited. ;-) If I e.g. use: "<INPUT TYPE=SUBMIT NAME="Absenden" onClick="return handleClick();>" the attribute 'required' of the mandatory input elements will be ignored !!!... Could you specify this button definition in detail, please? This post has been edited by Freddz: Jan 8 2019, 09:45 AM |
Christian J |
Jan 8 2019, 12:39 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Could you specify this button definition in detail, please? Something like this: CODE <?php if(isset($_POST['Absenden'])) { // put form handler script here echo "Form was submitted."; } else { ?> Form is not submitted. <form method="post"> <INPUT TYPE=SUBMIT NAME="Absenden"> </form> <?php } ?> Sidenote: QUOTE I check the mandatory inputs client-sided by the attribute 'required' Note that client-side form validation can easily be circumvented by malicious users, so always validate the form on the server-side as well. The above PHP only checks if some POST form was submitted, it doesn't check if all form fields were included in the form submission, or if the data is valid or safe to use. To be on the safe side, run isset() on all the form fields, sanitize the data from all of them as well with e.g. htmlspecialchars(). Further checks might be required before creating an email or querying a database. |
Lo-Fi Version | Time is now: 25th April 2024 - 09:02 AM |