Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Capturing Input From A Form


I currently have a search form on my website. When you type something in, it redirects you to a page that displays the results. I would also like the users searches to get input into an access database at the same time.

How would I do this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Capturing Form Input
I will try to be short and to the point.(good Luck) I have a form
written in HTML. I have a Mysql database. I am using a linux server
and I would like to use php to write the following code:

After the user inputs their name, address, email, phone, etc. in my
html form. They will hit the submit button. I need for the information
they entered to go into my database.

I have looked now for about 12 hours and haven't been able to find an
answer. I know I must be missing something since I've been to the w3
site, codewalkers, phpfreaks,php.net(?), and many more.

If there is an easier way of doing this I would love to hear it.

If somene could point me in the right direction I could stop banging
my head and pulling my hair.

Capturing Results Of A Form Submission
Is it possible, in PHP, to capture the resulting HTML of a submitted
form returning from a server and incorporate that HTML into say a
table, or some predefined layout?

I am trying to incorporate the resulting HTML into a layout I have
created in order to keep the look & feel of my site consistent, but
the resulting page is a plain "cheesy" page.




Capturing Chinese/Korean Characters In A Form?
I am new to PHP and have been asked to create an HTMl form that captures data onto a text file. I have that working fine.

I now need to capture Chinese/Korean characters from this same form and onto a text file. How do I do this? Is it possible to have one form that can capture US Alphabet and Chinese/Korean characters?

Input Form
First question:

I have an input form that upon pressing a button validates the values
entered into this form. I am using the following code recall this form if
there is an error in one of the requested fields:

<form name="form1" method="post" action= "InputForm.php" >

All works fine. However, if there is an error and this form is recalled, all
the fields are blanked out when you are brought back to the form. I'd like
for the form to retain the values that had been entered. How do I do this?

Second question:

For the fields that are in error, I'd like for the titles for the fields to
display an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?

Input Form With Same Name
I have a problem with a form that it has of the input with the same
name: I cannot modify code HTML inserting [ ], in the variable $_POST
is always a single value, like I can recover also the others?

Input Form
I'm trying to set up an input form so when I enter information using the input form the info I type in is sent to another page and placed in a table. That I already have set up but when I hit the refresh button the data in the table is erased. Code:

Form Input Must Be Multiples Of...
I am trying to make an order form and i want to make sure the quantity input is in multiples of 20. I don't want to use a drop-down box because the range can be 0-1000. Is there a function that will return whether a value is an integer?

Form Input Into Arrays?
When passing form inputs to another php page, I know that a form field named field1 will pass the value to the next page in a variable named $field1.

However, is it possible to pass the field directly into an array? I ask this, because my forms are generated dynamically, and each form field is numbered - so I would like to pass the values into the appropriately numbered slot in the array for the next page.

I Want To Use PHP To Process Input From A Form
I want to use PHP to process input from a form,
How can I do it?

Checking Form Input
Well i've eventually manage to get a comments system working on my site, adding information etc. however i want to add a few saftey precausions.

I.e prevent use of HTML commands been enterend into a comment or holding down a single key, that can often lead to tables been pushed out of size, thus messing up the site. i have been using a function that strips out swear words, this works fine, I included an option to remove HTML etc... using PHP Code:

Formatting Form Input
I have a simple lweblog that I made for a website using php and mysql but I noticed that what I enter in the form is not what gets outputted. I want to have returns and spaces and and things like that. Does anyone know where a good place to learn how to do something like this? Or maybe tell me what to put in my code?

Capitalization Of Web Form Input
I'm using PHP to submit form input to MySQL and need a way to
capitalize the first character for certain fields. Does anyone know of
some way to achieve this?

Plus Minus Form Input Box
Can any one help me with a script that will increase or decrease the value in a form input box each time either a plus or minus charachter is clicked on?

Much like what you would have in a shopping cart, a form input box with say a number 1 default in it, you will have a + and - charaters next to the box and if you click on the + the number in the box will increment 1 and if you click on - it will decrement 1.

Rendering Form Input
I created a basic forum. If someone tries to post something like the following:
I ' m   r e a l l y   b o r e d .It comes out like this:

I ' m r e a l l y b o r e d .I know it's an HTML limitation.

What can I do so what it will render every character typed? Here's my code:

Cleaning Up User Form Input In Php
Does anyone please know why when trying to clear up user input that has been entered into a form, php only clears up most of it and not all?

For example, using stripslashes to remove all slashes from a variable after a user has submitted quotation marks ("") into a form.

The quotation marks cause the variable being parsed to contain slashes.

e.g. a user enters """""" into a form , the variable returned to php becomes """""

So if I only wanted the quotation marks, I thought the stripslashes function would achieve this.
However, it only removes 3 of the 5 slashes leaving 2 unwanted slashes behind.

Keep The User’s Input Showing In The Form
I am working on a model which contains more than ten pages. There is a form on each page to let the user enter the information. I used session to store the user’s input for each form, so I don’t need pass the input information from each form with $_POST[‘smth’] all the way down to the last page which calculates the result based on the input. My question is HOW TO KEEP THE USER’S INPUT SHOWING IN THE FORM, so when the same user wants to do another calculation by changing only a few inputs not all, the user can only change the one he wants to change, all the other information stay the same as the last round of calculation. For example, the program requires the age, # of courses taking, the score for each course. When the user wants to use this model more than once and he/she only need change the score for each course, all the other information still use the input from the first round. Do any of you have any ideas? I hope I have described my question clear enough for you to understand.

Form Input Error Checking
Have a form field being inserted, needs to only allow an integer value through. Which function do I want to use to check the passed var to see if there are any non-integer values present? PHP Code:

How To Limit Form Field Input?
I'm wondering if there is an easy way to limit a user's input in a text field to 1000 characters?

Contingency For Form Input When Db Is Offline
My mysql server and web server are on different machines. Potentially, the db server may be offline, but requests to add to the db may still happen. I would like to develop a contingency plan so when the php script can't connect to the db, it writes the form data in a text file and sends someone an email, with a link to process the information later.

My problem is there are textarea boxes on the form, so potentially the data could contain hard returns and such, which will throw off a script that would use file() and parse each line for a separate query. What other options do I have?

Form Processing With Input Validations
I am creating a form Form1.php that posts to the another form
Form2.php.

I have input validations on the first form. I need the user to go to
the next form ONLY if the inputs from the user are valid. I have not
been able figure out how to do this since the first form always posts
to the next form no matter what.

I would really appreciate if somebody can share their php knowledge
and give me some idea on how this is done in php.

Quotation Marks In Form Input
I have a form which contains a field for "height".

If someone places an entry such as: 5&#396;" the form seems like it completely
empties that value.

It does NOT do this on my machine, but does on the client's machine, which
leads me to believe it is something with their php configuration.

Any ideas on what this is (and how I can work around it?)

Duplicate Input In 2 Form Fields
Hope to check the input in two form fields:

input in "emailto" form field: a@a.com
input in "emailfrom" form field: a@a.com, b@b.com, c@c.com

I hope to remove the duplicated input "b@b.com" in "emailfrom" form output and then keep only the remaining part of the string. How can I do that? I have though a way in combining the two fields input as an array and then use "array_unique" to check the duplicate. And then, to separate the two fields input again.

How Do I Test Safe Form Input?
I am using Apache 1.3.x with PHP 4.3.x and MySQL v4.

Short question:
Before I put my web form available on the internet, how can I test it
from mis-use in such that special characters are ignored? I have tried
entering data such as `/bin/date > /tmp/1234` and this does not create a
temporary file (which is what I would expect, meaning that my form is safe).

Same question at greater length:
I understand how form input can be misused, and I understand that I can
clean the data input using addslashes() or by having magic_quotes turned
on. I have decided on the latter but want to ensure my form is safe and
that storeing my data in my mysql database isn't open to hacking by
CGI/Form manipulation. I have tried entering data such as `/bin/date >
/tmp/1234` and this does not create a temporary file (which is what I
would expect, meaning that my form is safe).

Have I tested it successfully against Form/CGI hacking?

Stripping Quotes From Form Input.
Is there a (better,quicker,easier) way of stripping anything other than text, and numbers without using an if statement to catch errors, and have them re-enter the info? I'd rather just strip them all together.

Something like.. if I want to stip out anything other then the alphabet, and 1-9, so I don't have entries that look like this.. Quote: ..%blah''''""""";blah!!!@@@~``

PHP Select Form Input Type ?
I want to be able to manipulate the order of data queried from mysql. The problem I am having is with the select input type for some reason I cant get it to recieve a value in an array? Code:

Generating Email From Form Input
I have a form on my webpage. I would like visitors to complete this
form and click a send button that generates an email. How can this be
done? With Javascript of PHP? In either case, please send me pointers
to where I can find more information. (I am an utter PHP noob.)

Validating Form Input Data
I am tying to come up with an elegant way to process some input data that
come from a form. When the user hits the 'Submit' button, i want the form to
appear again with the already entered valid data filled in and prompt the
user to re-enter the non-valid data. If all data is valid, i will forward to
an other .php page which enters the data into a database.

I tried to do this in the following way: the form always hits back on
itself, but when all data is valid i use the PHP:header() to redirect to the
data.php that performs the database insertion. The problem is that the data
is not available to data.php in the $_POST variable. How can i overcome this
problem? Any other subtle way to handle the whole thing?

Re-draw A Form With User's Input.
I try to write code for server side
data validation. Initially, I have a html file called "form.html" which
just contains all the necessary fields for user to submit their contact
info (name, phone, email, address.....etc...). All user's input will be
sent to "processForm.php" using POST. In processForm.php, I want to be
able to re-display the form in "form.html" with valid user's input and
error message on top of the form in case user enter invalid data.
Currently, a simple code that I could think of is the following:

<?php

if (!empty($_POST['submit']))
{
$isAllValid = false;

//Check for invalid data
//Code for checking data will be written here.

//Invalid data occur.
if(!$isAllValid)
{
include("form.html");

//set user's input in the form's fields. How to access
//form's field form here ?
}
}
else
{
echo "User not submit";
}

?>

My questions are:

1. Is there a way to access the form's fields in "form.html" to set
their values ? (given all the form's fields in form.html have unique
name)

2. If (1) is not doable, then how would I this in PHP ?

Input Form + Umlauts + Strtr
I have an input form which needs to be able to handle umlauts (eg: ä ö etc..) and passes them via POST to a php file I have created. In my php file I have the following code:

// Convert accents and extended characters into english equivalents.
$characters = array( "'" => "", "&" => "And", "(" => "", ")" => "", "-" => " " );
$umlauts = array( "ä" => "ae", "ö" => "oe", "ü" => "ue", "ß" => "ss" );
$replacements = array_merge( $characters, $umlauts );
$beer_name = strtr( strip_tags( trim( $_POST['beer_name'] ) ), $replacements );
In my header I have the following code to allow/force utf-8:

// Setting the Content-Type header with charset
header('Content-Type: text/html; charset=utf-8');
When I try to echo any content, or use it in a mysql table the $characters part is correct and is converting things like the & to And, but the umlauts section is ignored and ä etc.. is echo'd to the screen instead of the converted string, in this case 'ae'. This leads me to think it has something to do with either how the form is handling the POST content and/or I'm using an incorrect character set?

0s Instead Of Blanks/nulls In Input Form
I have an input form in php that saves to mysql, when I leave blank fields they save as zeros... Anyway to go around that? Here is the code:

Figuring Out Secure Form Input
I'm trying to figure out how to do this while hoping it's the right way to do it;

The part that determines if user inputs "ANY IRREGULAR CHARACTERS OR CODE" (sql/php) what I don't know how to do.

$inputerrors = "You've had some inputting problems, dude."
if($_POST['article_title'] HAS ANY IRREGULAR CHARACTERS OR CODE)
//then return;
$inputerrors .= "It seems as though you're trying to pass code into our servers. Your IP address is $gosun and your ISP is $goto. A likely photo and address of you may be $crossreferenced. If this happens more than 3 times, you will be banned and $goto will be informed of any malicious conduct. If you would just like to hack please go to my hacking server and have some educational malicious fun there.";
echo $inputerrors;
exit();

Input And Output In Same Form With Edit Facility
i am using MYSQL with php. the databse is containing the deatils of the stock of each supplier. i want to update the stock so i will enter the name of the dealer.i should be shown the existing stock and from ther only i should be able to edit the stock to update database.

How To Check Form Input If It Has Evil Caracters In It
I have a script that accept input from a form. What should I check (and how)? I though first I shoul check with the W to find all variables with carcters other than letters and numbers. But I need to accept other caracters (caracters with accent marks) too!

Please help and send me some actual code I can paste!

Have You Ever Done A SUPER Form Processor That Will Use ANY Input Vars?
What I mean is or what I'm thinking of doing for my company since they are starting to ask me to replace the old spreadsheets with a SQL database with web based forms etc...

Well normally I create a processor for each form. What I'd like to do is a general processor so lets say form A sends the vars ($products, $name, $numbers, $something) and form B sends the vars ($more, $steve, $blah, $imagination). And of course I'd add some hidden vars in each form to tell my processor which database to update/add etc... such as $database and $table vars... and maybe one to tell the action $action ="update, add, delete)...

This sounds like a security hole to me but I can fix that by only accepting post vars and only referers from my server so I think no one from the outside could post vars to my processor...

But how would I go about doing this? I'm thinking variable variables or having each form send an array. And in the processor use the array's key as the table's column and the value as the value?

So I'd have: $array (column => stuff, column2 => more stuff, etc...)
and $database = "steve", $table = "duh" $action="edit"

But I don't know how to use all the data in my array to make the SQL statement? I know how to get stuff, more stuff but getting the keys? And since they are never the same nothing can be hard coded.

PHP Displaying Info Input On HTML Form
I'm in an exercise where I've created an order form in HTML. The form displays properly and allows me to input certain test order info just fine. The relevant lines in the HTML form are: Code:

Does Anyone Declare A Different Data Type On Every Input In A Form?
I'm trying to read up on the rfc's that govern form inputs. Much of
what I'm reading is stuff I didn't know before and some of it is
alarming. This one left with me questions:

Is this (below) addressed to me as a web designer, or is this
addressed to the makers of web browsers? Identifying the type of file
being uploaded seems way outside of my scope as a PHP coder. Am I
suppose to make clear the expected type of content when I design a
form? Off hand, I can only think of two things that every go into an
HTML form: strings and binary data. Should I actually label every
INPUT with the expected type (does anyone do this?), or can I assume
the makers of web browsers have already done that for me? My PHP form
code is fairly concise, so I could add in mime/text rather easily, but
is it necessary? Surely the browser knows that everything save binary
files is a string?

They wrote:

3.3 use of multipart/form-data

The definition of multipart/form-data is included in section 7. A
boundary is selected that does not occur in any of the data. (This
selection is sometimes done probabilisticly.) Each field of the form
is sent, in the order in which it occurs in the form, as a part of
the multipart stream. Each part identifies the INPUT name within
the
original HTML form. Each part should be labelled with an appropriate
content-type if the media type is known (e.g., inferred from the
file
extension or operating system typing information) or as
application/octet-stream.

They give the example below. Am I right to say that I don't need to
think about any of this, that the web browser does all this
automatically? The browser figures out that file2.gif is a gif image
that needs to be sent with a the header Content-type: image/gif, yes?

If the user also indicated an image file "file2.gif" for the answer
to 'What files are you sending?', the client might client might
send
back the following data:

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed, boundary=BbC04y

--BbC04y
Content-disposition: attachment; filename="file1.txt"

Content-Type: text/plain

... contents of file1.txt ...
--BbC04y
Content-disposition: attachment; filename="file2.gif"
Content-type: image/gif
Content-Transfer-Encoding: binary

...contents of file2.gif...
--BbC04y--
--AaB03x--

If I wanted to send multiple
files as part of a form input, how would I use the multipart/mixed
header, or the "content-transfer-encoding" header? Can anyone point me
to an example, so I might have a better chance of understanding this?

As with all multipart MIME types, each part has an optional
"Content-Type", which defaults to text/plain. If the contents of a
file are returned via filling out a form, then the file input is
identified as the appropriate media type, if known, or
"application/octet-stream". If multiple files are to be returned
as
the result of a single form entry, they should be represented as a
"multipart/mixed" part embedded within the "multipart/form-data".

Each part may be encoded and the "content-transfer-encoding" header
supplied if the value of that part does not conform to the default
encoding.

Trouble Passing Form Input To C Program
I'm using exec to start a C program and need to pass it some parameters from a form. It works fine if I hard code sample parameters into the exec call like so:

exec('/var/www/argtest 2000 March', $output , $returnStatus);
With the following, the C program runs but the parameters do not get passed:
exec('/var/www/argtest $year $month', $output , $returnStatus);

I searched the forum and found an entry indicating that I should be able to include those variables like that. What am I doing wrong here?

Thoughts On The Best Way Of Highlighting Form Input Errors?
I've been creating an application over the last few weeks and generally
pleased with what I have produced but one area is irritating me, form
validation.

At the moment the forms are simply static html templates and the form input
is checked using a validation class. Basically each form field is checked,
every error is stored to an array and at the end of checking of the complete
form, the array is output neatly at the top of the form.

However this is just not sexy enough for me, what I would like to happen is
for the input boxes with errors to be highlighted with a red border (or
something along those lines). I would also like to have the error messages
under the box which the error occured, not altogether at the top of the
page.

So I am currently wondering how to achieve this and what choices are open to
me on methods available? I've had a google around the web and found some
form validation classes but they basically do what I already achieved. I've
thought of creating the forms dynamically but that in itself doesn't address
how to achieve my goal.

I am sure many people have already successfully done this, if you have the
please could give me an outline (the theory) of how you did it. I don't want
or need code, I am simply stuck at the moment on how to approach this.

Getting The File Path From A Html Form Input
I want to get the file path from a file input field, not just the filename. I don't have to necesarily use the input of type 'file', but that is the only way i know how to have a browse button.I tried using javascript to fetch the content of the file with this function:

function GetDirectory(){
   strFile = document.FileForm.filename.value;
   intPos = strFile.lastIndexOf("");
   strDirectory = strFile.substring(0, intPos);
   alert(strDirectory);}

but i don't know how to pass the javascript variable to the php.

Form Input Page To Sort With Link
I'm looking to create a page that a user can input data into a form and submit it to a mysql database.  From there I want another page to display the data sorted by a certain field of the data that was entered (i.e. Year) and then be able to click on the field that is sorted by (Year) and go to another page that displays all of the information that was originally entered.

Take Each Input From A Form And Convert It Into A Session Variable?
I have a huge form with 40 text input fields.  Each text field corresponds to a record in a mysql table and was generated using mysql_fetch_row().  Is there an easy while or for loop i can use to populate the $_Sesssion array for each text input?

Validating A Country / State Form Input
I'm having trouble validating a state and country input. I didn't write it so I'm confused about why my code isn't working with it. Code:

Double Input Of Form Data When Browser Is Refreshed
I have a form page. When submitted it posts to page2.  On page 2, it inserts variable into the database. The queries the database and displays the information. But....

If the viewer refreshes their browser, it now submits the information into the database again.

Not sure how to handle problem. I think that if a session variable passed to page 2 in an if else statemen, it will keep this from happening when refreshed since the session variable is not passed in the refresh. 

Preparing Mutiple Values For Hidden Input To Form
I have a requirement to enter values in a form in the following format.

<input type="hidden" name="item_name_1" value="Item_name_1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item_name_2">
<input type="hidden" name="amount_2" value="2.00">

In my application the item name = $title and amount=$price
I have code which extracts the title and price but I cant figure out how increment the item_name_x and amount_x by 1, starting from 1, for each item purchased. Code:

Clearing The Input Text Field After Submiting The Form To A New Page
I have a page with a form with an input text field ... and when a user types his/hers ID ... and submits the form - his/hers page opens in a NEW window .... but the value (ID) that was written in the original window remains.

I want to make sure that the form input field on the original page becomes "invisible" - by refreshing/reloading the original page or just by clearing the input form after submission.

For now I have put in a meta refresh tag in the head of the html file ... but that is not the solution ... becouse I only need a one time refresh/reload of the page ... and this is to happen right after the input text value is being submitted.

Checkbox Form Field Making Sticky And Remembering Input
I'm trying to get a form with checkboxes to be sticky and to remember what the person checked.

I am using sessions and when I echo the results of the checkboxes the correct result appears. Thus far, all the code I've found makes all the boxes checked.  After the person clicks submit, I only want the boxes checked that the person checked. Code:

Detecting URL's And Html Tags In Text, Input From Form
Is it possible to check text and set a PHP variable if someone inputs links, <h1></h1> ect. and other html tags when filling out your form mail or guestbooks?

How To Update Form Input Field Background Colour On Validation Error
I have been searching for form validation scripts for ages and all th ones that I like are far too complicated and inflexible so I decided to stick with my own which is easier to understand.

The only thing I don't like which i have seen on better form validation scripts is that and fields with errors are highlighted.  i can only presume that they have used php to set the background color of the input field or textarea.

How would I add some code to change the background colour of form elements if an error is found? Here is my code which validates the form but doesn't change form elements colours. Code:

$_POST Behavior From Input=submit Vs Input-type=button
I have been trying to solve an annoying behavior with PHP (I think).
Maybe some of you have encountered the same and have some ideas.

I have an html form and I use an <input type="button"> element with
the onClick event that calls a javascript funtion. Once the script's
content has been processed, I execute the form.submit() directive.

I would like to combine the html form and the PHP script into one, and
use action="<?php echo($PHP_SELF) ?>".

When the html form has <input type="button" name="theButton"
value="thisisthetrigger" onclick="doThis(this.form)">but PHP cannot
'read' the value of $_POST["theButton"] after form.submit().

If I substitute the <input type="button"> for <input type="submit">
then PHP reads the value just fine. Some may argue to just use the
latter option, but that will cost me a trip back to the server to
basically do a lot of validation that can be very easily accomplished
on the client side.


Copyright © 2005-08 www.BigResource.com, All rights reserved