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 14 2019, 01:58 PM
Post
#2
|
Novice Group: Members Posts: 25 Joined: 7-January 19 Member No.: 26,791 |
I meanwhile think the basic question ist just a simple one here:
How can be detected that the 'required' attribute is fulfilled? (that any mandatory field is set) I suppose that there is a page submission as soon as 'required' is fulfilled from all the field elements. Isn't that correct?? So then the php script to make an db insert has to be started. That's it, isn't it? So isset should not be really necessary!?... Instead shouldn't e.g. the following architecture generally work then?... +++++++++++++++++++++++++++++++++++++++++++ <script> function DBinsert(){ <?php echo "Form was submitted. Place the DBinsert code here!"; ?> alert("Field data saved successfully!..."); } </script> <form id="myForm" method="POST" action="" onSubmit="DBinsert();"> <select id="choice" name="choice[]" multiple required> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> <option value="4">four</option> </select> <input type="submit" name="btnsubmit"> </form> +++++++++++++++++++++++++++++++++++++++++++ Action="" means that success message is not shown on another page. Instead a function is executed via onSubmit event which contains the DBinsert php script. So why shouldn't that work fulfilling all my client-side conditions, Christian?... Note: Of course you could use isset instead of onSubmit as well, replacing function DBinsert by isset's if condition!?... Please let me know which mistake I do here. This post has been edited by Freddz: Jan 14 2019, 02:06 PM |
Lo-Fi Version | Time is now: 21st September 2024 - 06:11 AM |