Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-11-2010, 03:52 AM   #1
Bronze Member
 
Join Date: Jul 2010
Posts: 45
Default Basic form processing questions

I have a form collecting data and inserting it into a mySQL table.
The processing is done by a php file.

My opening form tag looks like this:

<form action="php-form-processor.php" method="post">

The problem I have is, after the data is processed and entered into mySQL, I end up looking at a blank page - the mysite/php-form-processor.php page.
How can I avoid displaying the page and having a small pop up reading "Data successfully stored" instead.

Data validation in done in the same php file. How can I quit the script, before executing the INSERT query, in the case data validation rules are not met?

Any ideas will be greatly appreciated.
bigcougar is offline   Reply With Quote


Old 11-11-2010, 05:01 AM   #2
Gold Member
 
smoovo's Avatar
 
Join Date: Oct 2010
Posts: 388
Default

The page you are sending the data from, will contain "if else" statement, and the "php-form-processor.php" will head to the page back.

More clearly:
1. Your form page will contain "if else" statement, this will ask the question if the page loaded with "GET" variable or not. If not => show the form, else => show message.

2. When form is submitted, it goes to "php-form-processor.php" and store the inputs. When done go to "your-form-page.php?ok=1". "ok" is your "GET" variable. If there is error you can send header with "?ok=0".

3. Now we back to "your-form-page.php" with "GET" variable. So our page will show message. If "$_GET['ok']=1" post "Thank you..." if not, post "Sorry...".

- Enjoy.
__________________
SMooVo - Web Design & Development
contact@smoovo.com
www.SMooVo.com
smoovo is offline   Reply With Quote
Old 11-13-2010, 01:18 AM   #3
Bronze Member
 
Join Date: Jul 2010
Posts: 45
Default

Thank you Smoovo,

It is still a little murky for me. Do you know of a site that may have explanations/examples.

I did not use any JavaScript processing, and the example I found (which basically works) is only using a php file for storing data in mySQL by the method "Post". That example either skipped some important data validation steps in JavaScript, or the JavaScript part is not needed in some cases.
bigcougar is offline   Reply With Quote
Old 11-14-2010, 07:52 AM   #4
New Member
 
Join Date: Nov 2010
Posts: 6
Default

Quote:
Originally Posted by bigcougar View Post
How can I avoid displaying the page and having a small pop up reading "Data successfully stored" instead.
Call php-form-processor.php from an ajax request and code its success result with the "small pop up".
EvilivE is offline   Reply With Quote
Old 11-16-2010, 04:12 AM   #5
Bronze Member
 
Join Date: Jul 2010
Posts: 45
Default

Quote:
Originally Posted by EvilivE View Post
Call php-form-processor.php from an ajax request and code its success result with the "small pop up".
Does this mean I have to first assign the values of my form boxes to JavaScript variables and then pass the values to the PHP processing file?

Something like this:

var form_field1 = document.getElementById('Form_field1').value;
var form_field2 = document.getElementById('Form_field2').value;
...

var url = "php-form-processor.php ?f1=" + form_field1 + "&f2="+form_field2;

My form has many fields and one of them is a big text (comments) field.

Thanks!
bigcougar is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:33 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.