The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Validating 'required' form page data for save to database, Saving by php code file after succesful validation. Success message on
Freddz
post 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">
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Jan 15 2019, 07:03 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Freddz @ Jan 15 2019, 08:14 AM) *

$sql = "INSERT INTO ... VALUES ('" . $_POST["Name"] . "', '" ... );"

The above is very dangerous, to avoid SQL injection exploits you should never use raw form data (such as $_POST) in the database query before sanitizing it. The sanitation must be done by the PHP script, not by the HTML form.

QUOTE

I can put this script also into the HTML form page code if it is more difficult with a php file.

I think that would be the simplest solution.

QUOTE

But as I said: Main condition is that the fields are validated by attribute 'required' !! I assume that such a solution should exist!

Yes, but it only works on the client-side (the browser), so it can't be trusted for security.

QUOTE

If this regardless isn't possible I begin to ask myself why this attribute is existing.

It's just meant as a convenience for users. As https://www.w3.org/TR/html/sec-forms.html#c...form-validation says, it "allows the user to avoid the wait incurred by having the server be the sole checker of the user’s input."

QUOTE(Freddz @ Jan 15 2019, 08:32 AM) *

If it means that we cannot use a function (javascript) because in this function a php code cannot be implemented directly but just via Ajax (which limits the possibilities) we still could use isset instead, couldn't we?
Cause then we may not need a function but can put the isset php code directly into the HTML code anywhere, right?...

Yes, but then you must submit the whole page (like in my first suggestion), so that the PHP can run on the server.

QUOTE(Freddz @ Jan 15 2019, 09:52 AM) *

Ah, this is also not possible, right?
isset can only be used within a php page file but cannot be nested into a html file!?.

PHP can be used in a .html file (if you configure the server that way). But PHP always run on the server before the file is sent to the browser (except when using Ajax).

QUOTE

I once created the site with Netobjects Fusion Elements. This doesn't support php page files but only html pages.
So do I only have the chance to use cgi script code to save form data of an html page file into a database (if I want to continue to work with NOF)?...

I don't know, but in general I advice against using WYSIWYG editors like these.

QUOTE

Or I have to use the action attribute to execute a php code

I assume you mean using different URLs for the form and PHP script?

QUOTE

but then have to accept that the success message cannot be displayed by a simple alert message window but only by a separate new page that "Action='dbinsert.php'" created?...

If the PHP page is loaded in an iframe, you can still make it produce an alertbox if that's what you want.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
Freddz   Validating 'required' form page data for save to database   Jan 7 2019, 08:34 PM
Christian J   Hello Hello, I have a form page where I check th...   Jan 8 2019, 05:56 AM
Freddz   Thank you very much. But how is the button (<I...   Jan 8 2019, 08:55 AM
Christian J   Could you specify this button definition in detai...   Jan 8 2019, 12:39 PM
Freddz   Another little question to you related to my probl...   Jan 8 2019, 10:10 AM
Christian J   Isn't there anywhere a nice, simple, powerful...   Jan 8 2019, 12:42 PM
Freddz   Hello Christian. I am very sorry but I do not unde...   Jan 10 2019, 04:57 AM
Christian J   But how could the php script be started?? What fr...   Jan 10 2019, 07:35 AM
Christian J   Here's another way of looking at it, where esp...   Jan 10 2019, 07:41 AM
Freddz   Hello Christian. Thank you again. But I still don...   Jan 12 2019, 04:29 AM
Christian J   But I still don't understand e.g. why there i...   Jan 12 2019, 05:55 AM
Freddz   Hello Christian. I think you think that my form p...   Jan 12 2019, 09:34 AM
Christian J   Let's give you a simple example of my form pa...   Jan 12 2019, 02:14 PM
Freddz   Hello Christian. Thank you very much. But once aga...   Jan 14 2019, 07:48 AM
Christian J   But once again your code begins with <?php aga...   Jan 14 2019, 09:53 AM
Freddz   So from your side you just cannot send me a soluti...   Jan 14 2019, 11:54 AM
Christian J   So from your side you just cannot send me a solut...   Jan 14 2019, 01:05 PM
CharlesEF   I posted a $_GET Ajax example a couple of wee...   Jan 14 2019, 12:52 PM
Freddz   I meanwhile think the basic question ist just a si...   Jan 14 2019, 01:58 PM
Christian J   How can be detected that the 'required' a...   Jan 14 2019, 03:31 PM
CharlesEF   If you want to make sure your required fields are ...   Jan 14 2019, 02:19 PM
Christian J   Also, 'onSubmit' isn't a valid form a...   Jan 14 2019, 03:36 PM
CharlesEF   Also, 'onSubmit' isn't a valid form ...   Jan 14 2019, 04:44 PM
Freddz   Hello Charles. Thank you for your time! My goa...   Jan 14 2019, 06:09 PM
Freddz   Would you please show me the code that uses Ajax? ...   Jan 14 2019, 06:23 PM
CharlesEF   Would you please show me the code that uses Ajax?...   Jan 14 2019, 09:19 PM
Freddz   Hello Charles. Yes, I use POST. The PHP script is ...   Jan 15 2019, 02:14 AM
Freddz   If it means that we cannot use a function (javascr...   Jan 15 2019, 02:32 AM
Freddz   Ah, this is also not possible, right? isset can on...   Jan 15 2019, 03:52 AM
Christian J   $sql = "INSERT INTO ... VALUES ('...   Jan 15 2019, 07:03 AM
Freddz   See, Christian, we meanwhile have discussed about ...   Jan 15 2019, 09:23 AM
Christian J   Obviously at each method there is at least one di...   Jan 15 2019, 12:33 PM
CharlesEF   Attached is an example of a $_POST Ajax funct...   Jan 15 2019, 01:58 PM
Freddz   I assume your solution 5 cannot be used as Netobje...   Jan 15 2019, 02:17 PM
Christian J   I assume your solution 5 cannot be used as Netobj...   Jan 15 2019, 03:50 PM
CharlesEF   I forgot to say that you didn't post enough ...   Jan 15 2019, 03:53 PM
Freddz   I forgot to say that you didn't post enough ...   Jan 18 2019, 09:13 AM
CharlesEF   Additional form elements I would add just by addi...   Jan 18 2019, 02:37 PM
Freddz   I forgot to say that you didn't post enough ...   Feb 12 2019, 11:58 AM
Freddz   To solution 1: The idea with the iFrames is a good...   Jan 18 2019, 07:36 AM
Christian J   To solution 1: The idea with the iFrames is a goo...   Jan 18 2019, 12:44 PM
Freddz   Yes, I know that I have to edit the generated file...   Jan 21 2019, 06:52 AM
Christian J   I added an .htaccess file in the html folder with...   Jan 21 2019, 11:09 AM
Freddz   Afterwards I tested your last suggestion, Christia...   Jan 21 2019, 07:13 AM
Freddz   My code is okay, isn't it?... Yes, I have a r...   Jan 21 2019, 05:27 PM
Christian J   My code is okay, isn't it?... The PHP yes, o...   Jan 22 2019, 05:55 AM
CharlesEF   The main problem I see is your use of 'getElem...   Feb 13 2019, 01:07 AM
Freddz   Oh thank you. So I changed from ByName to ByID aga...   Feb 13 2019, 11:13 AM
CharlesEF   Nothing in 'dbinsert.php' jumps out at me,...   Feb 13 2019, 12:01 PM
Freddz   Nothing in 'dbinsert.php' jumps out at me...   Feb 13 2019, 09:59 PM
CharlesEF   I still see the same problem. You did change the ...   Feb 14 2019, 10:19 AM
Freddz   Ohhh, you are sooo great!! Now it works ...   Feb 15 2019, 01:34 PM
CharlesEF   Glad to hear you got it working (after shooting yo...   Feb 15 2019, 03:40 PM


Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 03:12 AM