Form Field Value Containing Backslash
I have recently taken up PHP programming, and I got stuck on the
following.
<?
$p_body = (isset ($_POST['body' ]) && ($_POST['body'] != '')) ?
$_POST['body'] : 'Enter your text here'
$p_name = (isset ($_POST['name' ]) && ($_POST['name'] != '')) ?
$_POST['name'] : 'Enter name'
$p_mail = (isset ($_POST['mail' ]) && ($_POST['mail'] != '')) ?
$_POST['mail'] : 'Enter email'
$output = <<<CODEREH
<form method="POST" action="doform.php">
<p><input type="TEXT" name="name" value="$p_name" /></p>
<p><input type="TEXT" name="email" value="$p_mail" /></p>
<p><input type="TEXT" name="body" value="$p_body" /></p>
<p><input type="SUBMIT" value="Store it!" /></p>
</form>
CODEREH;
$invalid_body=array('','Enter your text here');
$invalid_name=array('','Enter name');
$invalid_mail=array('','Enter email');
if (validate($p_body,$invalid_body) && validate($p_name,$invalid_name)
&& validate($p_mail,$invalid_mail)) // fields not entered correctly
{
//process form data and provide link to continue (or enter another
set of data)
exit;
}
// data not entered correctly
echo "All fields must be entered!";
?>
If either field contains backslashes, they are duplicated when the
form reloads.
Each successive form submission becomes , \, \\ etc etc
Why does this happen and how do I fix the variables to show the
original data each time?
I know I am a newbie, probably an easy one for this group.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Add Form Field Values Into Php Seesion Variable Before Submitting The Form
I have php page which is basically a simple html form containing some text fields.The user will type in values in it and submit it .Now what i want is that just at the time of submittion i want to assign the form field values in session variables. I nwwd this b'coz the form is being submitted into a cgi script which has been given to me.Now the cgi script is an executable one and i am unable to view or change its content,Its functionability is to change a password for a linux user account .Now the cgi script after completing the job is redirected to another html page.What i have to do is that i need to trap the user input and update the values in a mysql database .Now if i can assign the values in a session variable then i can do the updatation from some later pages.
Magic Backslash
Can someone direct me to a page saying what the rules are for the backslashes being added by PHP? I read somewhere that they're automatically done for $_POST and $_GET, but I have the following: Code:
Trailing Backslash On URL Problem
Can anyone tell me if this is a confiuration problem in my httpd.conf file? I recently installed Apache, and moved an old PHP application to the new server. I haven't done anything that I haven't done a million times before to my conf file, but when I try to e.g. access http://myhost.com/admin I get a 404, but if I add a trailing backslash (http://myhost.com/admin/) then it works. Any ideas anyone? I would have posted on an Apache newsgroup, but there doesn't seem to be much activity on any of the 3 I found.
Text Box Value, Backslash, And PHP Variable
I have a form with a textbox. On submitting the form I read the textbox value into a php variable. If the value in the text box contained a ' or " anywhere in the string, the php variable adds a backslash ahead of the character. How can I get rid of this unwanted backslashes?
Replacing Backslash With Entity?
How can I get php to replace a backslash with the equivalent entity? I tired this: $str = preg_replace("//i","",$str); But I get an error.
How Do I Get PHP To Save A Backslash In A Mysql Table?
I have a field in which a user inputs a Windows style directory path, hence using backslashes and not forward slashes. Example: c:qbdatamydatadile.qbw However, when the use clicks update, what gets saved is: c:qbdatamydatadile.qbw Does anyone know if there is a work around? The backslashes mysteriously are stripped. I use the following function to wrap each variable that's saved in the MySQL table: function update_database($value) { // Addslashes if (!(get_magic_quotes_gpc())) { $value = addslashes($value); } // Quote if not a number or a numeric string if (!is_numeric($value)) { $value = mysql_real_escape_string($value); } return $value;
Backslash Appears In Text Fields With Apostrophes
In <input type="text"> and <textarea> fields, when I enter a string that contains an apostophe, and then re-display the page (e.g. after an insert or update), the text changes to add a backslash in front of the apostrophe. If I leave the screen, and load the record fresh, the single backslash is not there. So I know it is not being saved in the database. For example say I type "This isn't my dog" into a field and press save on my screen. When the form is re-displayed, the string has changed to "This isn't my dog". If I save again, I get "This isn't my dog", and once more I get "This isn\'t my dog. It appears that the apostrophe and then each backslash is being "escaped" each time. I assume this is PHP's way of "escaping" special characters, but they end up getting stored in my database if I save a screen twice or more in succession. I this supposed to happen? Is there a way to eliminate this "escaping" behaviour in PHP?
Trying To Include The Literal '' (backslash) Character In A Regex
I am trying to include the literal '' (backslash) character in a regex. I am not sure if I need to escape it, however... From http://www.regular-expressions.info/charclass.html: "To include a backslash as a character without any special meaning inside a character class, you have to escape it with another backslash. [x] matches a backslash or an x." From http://www.tin.org/bin/man.cgi?section=7&topic=regex: "...all other special characters, including `', lose their special significance within a bracket expression." These seem to contradict each other. Both ways *seem* to work, but I am not familiar enough with regex's to know if one is producing some other side effect that I am not aware of.
Form Field To Array
Ok, two questions: 1) I have a mulitple select form field. It is named 'artists[]' and it produces the array artists[$i] correct? now i want to make the array into a single variable named $artists that containes the array in a CSV format with no ending comma. how do i do that? 2) Is it possible to browse for a directory and pass it though a script as text? not a file, just a directory?
PHP Form Field Update...
I am sure this has been answered here somewhere, but I have searched for a good 2-3 hours and can't seem to locate a solution. Additionally, I really don't want anyone to solve this mystery for me (at least not all the way!) - But I was hoping someone could point me in the right direction here. I am trying to figure out how to update form field information before the end user hits the submit button - for example, if they select that they are from California from the "state" drop down list, only counties from California would show up in the "county" drop down list. BTW, this is only a hypothetical example - I am only using this code to build a photo manager for my website! Anyone able to: 1) tell me what this process is called - it's hard to search for answers when you don't know what you're looking for. 2) point me in the right direction of a solution.
Form Field Testing
I have this site which people submit sites to it. What I need is for when they submit their info to the form, they enter their url into the form field and then next to that there is a test button, when they click this button in a new window it will load their site. I know there is a way to do this with java and php but not sure how to do it. Also is there a way to have it so their site is scanned and if it contains popups they will be denied access to join?
Form Field Set Focus?
I'm still something of a newbie to html/php/mysql. I have a php/html form with several fields of type "input". If the user enters improper data in a particular field and clicks the Submit button, the php script has to trap it and return a javascript error message box with an OK button. That part I've already got down. But, you know how in Visual Basic you can set the focus on the offending field on a form, so if the user gets a Message Box with an error message and clicks OK, the form goes something like, myForm!myField.SetFocus Is there an equivalent way in php/html way do this?
Splitting A Form Field
I am coding a form which stores info in a mysql DB. The form is ment to post and edit info on antiquarian books. My title field (<TEXTAREA>, so i can't give a maximum of characters) cannot contain more than 255 characters, but some books might have a longer title. I want to cut off all chars that exceed 255 (words should remain intact) and paste them into the description field. How can I accomplish this? I can count the chars with strlen , but how do I chop off the chars which exceed the maximum, keeping the words intact and paste them in another field?
Variable In Form Field
I want to put a variable as the content of a hidden field. I realise that normally you would just open up a set of php tags and echo the variable in which I have done in the past, although I need the whole form in php tags as I have made the form a function in order to hide it with sessions when no body is logged in. This seems to be causing a problem as I can't get the content of the variable into the field its just echoing the actual statement in. Code:
Form Field Validation
When validating user input I check it's not empty and then run 'mysql_real_escape_string($s)', I was then going to make sure that it is only alphanumeric, but I wanted to allow certain other characters as well. Realising this must be done before the mysql escape check, what characters should be blocked because they are dangerous, I can only really think of quotes and $. The real escape check should handle the quotes issue, so is the $ an issue or not?
Form Field Content And Sessions
I've searched for this and found similar problems, though not quite what I'm after. Basically, I'm using sessions for logins, keeping user data readily available etc. but when a user submits a form and then uses the back button to return to the form (if an error is given through some fields not being filled for example), the form fields are emptied unlike normally when it keeps the data you submitted. Is the solution to this simply the session_cache_limter() trick or is their a better, more backwards-compatible solution? I ask as I'm running PHP 4.0.1 at the moment so haven't been able to try it yet. Any help/suggestions are much appreciated.
Form Field Dynamic Population And PHP
I have a form that dynamically generates a drop down from a table column called suppliers. Products supplied by each supplier vary so what I want to try and achieve is that once a supplier has been selected a second drop down on the same page is populated with data from the same table / different column with that suppliers products. (I am trying to avoid refreshing the page) I have not supplied any code at this stage as I am not sure whether PHP is capable of doing this by itself or whether javascript would need to be incorporated.
Autmatic Form Field Fill
I have two fields in a form. The first is the email field the second is the username. Now I want the username field to be filled automatically with the part before "@" of the first field. So if someone fills in "brain@domain.com" the second field has to be filled with "brain".
Form Text Field Validation
I've got a form and I'm now trying to validate the text fields in it. The field I want to validate is for someones name, so there should only contain letters. Below is the function I've written to handle this. Code:
How To Hide 'hidden' Form Field?
I am sending the user's password in form's hidden field as Code: <input type=hidden name="studen_pass" value="readfromdatabase"> but i dont want anyone to read it via watching its source code. is there any trick to hide it with php so that no one can read the password hidden field value by watching page's source code.
Increment A Text Field In A Form
I am creating an intranet which shows active projects and allows people to add new projects. If users want to add a new project, they fill in a form but what I want the form to display in the ProjectNumber field (which is a var char field & not the primarykey) is the last Job Number incremented by 1. For example if the last ProjectNumber was TS0014, then the default value in the ProjectNumber field should be TS0015 - this way users know what the next job number is. At present, the last job number in my table is TS0014. Below is the code i'm using but for some reason in the Job Number field in the form Im getting TS001? WHY? Code:
Form Field Text Output
How can I get html code in an editable form field to display properly? Specifically: I have text that is echoed to a form field via <? echo $text ?> The user can then edit that text and submit. However <BR> is showing up as a literal <BR> and should be a linefeed. Is there a way to have this display properly? Example: LINE ONE<BR>LINE TWO should display as LINE ONE LINE TWO Note that this is only a problem in the form field. It displays properly when echoed outside of the form.
How To Get Un-escaped Text From A Form Field
I have a php script that gets the text from a form field: <?php include("global.inc.php"); pt_register( 'POST', 'test1'); echo $test1; ?> The text comes back fine, just some characters (', " and ) are now escaped (', " and ). The problem is that I need the he text to be exactly as it was entered by the user. I could process the text myself, and replace the escaped characters, but I'd like first to understand why this is happening and if there is a way to disable this behavior and get the unmodified text directly.
Php - Mysql Form Field Generator
does anyone know of a simple function/class that will take config options: table name and the database connection stuff(or whatever) It will then print out appropriate form fields to allow editing of a row? The reason being is that in the admin section of a website I am building we are constantly adding columns to a table...It is used for keeping config options of the site. We do not wanna update the form each time we add a column.
Web Mail Form Problem With One Field...
The code below is in my contactform.php file which takes variables from a contact form built in flash on my website. Three of my fields work correctly, but the phone field does not. It is always displayed as blank in the resulting email. I've tested the variable being sent from the swf on flash and the telephone variable is populated. Can anyone see the error in this code regarding $phone? Code:
HTML Form Field Value And Php Array
I am creating a html form which has 5 html list menu and menu value get store in array after hitting submit button. The value stores in PHP array and then print on same page and then after re checking the value If i want modification then click the edit button and value re store in the same html form. Here we are not using the database. If it is possible then please provide me the code and if there is any other solution to this problem them please guide me. for above problem please avoid the java script in php code.
Form Field *required* Validation
I have php form I'm trying to edit. Some of the fields on this form is required, and some aren't. I want to adjust it so none of the field is required. But I am not able to find the place to set this value. Following are 2 piece of the code for 2 fields, 1 is required and 2nd is optional. Please help me determin where I might be able to adjust the validation. Code:
Strpos To Validate A Form Field
I am trying to validate a form field. I have provided an example below. Basically I want to check that 'a' ($findme) is the 1st and 2nd character in the string (0 and 1 position). <?php $mystring = 'aakjhabc' $findme = 'a' $pos = strpos($mystring, $findme); // Note our use of ===. Simply == would not work as expected // because the position of 'a' was the 0th (first) character. if ($pos === 0) { echo "The string '$findme' is the $pos digit"; } else { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } ?> I am wondering, can strpos be used to find the specific character more than once in the string? As you see above, the 'aa' is the first 2 characters in the string. $pos equals 0 because it finds the first 'a' in the string, and I guess it doesn't look for the 2nd 'a'? If strpos can't be used for what I want, what other method can I use? I'd like to keep it in an IF statement and relatively simple. Any help much appreciated. Thanks for reading.
Automatic Select Form Field Default
I would like to allow registered users to my site the ability to change your personal information. Let's say the country in which they are in. The country field is a drop down list. So its supposed to read from the table and make the value the default. How am I going to do this?
Reading MySQL Data In A Form Field
i am in the process of building an admin page for a site. Most of my site data is being held in MySQL and being pulled using PHP. The problem I have is while trying to build an Admin form to change data in MySQL, I want to have the data that is currently in the table be automatically put into the form field, so they can see what they are changing before they change it, or so if they do nothing it keeps the same data in it. My code is as follows:
How To Change Form Field Contents In Existing PDF Using PHP?
Simple case: 1. I have a PDF file I made with Acrobat PRO. It contains a form with two fields, "Name" and "TestScore". 2. From my PHP file on linux server I just want to open this PDF file and change the content of the Name and Testscore form fields. Could someone show me a simple code example on this? And what do I need of addons? PDFlib and licences?
How To Process Dynamic Form Field Names
Let me start by saying I don't have a lot of PHP experience, and am just starting to fumble my way around some of this stuff... I'm sure this has been asked a number of times, but after 2 days of searching the internet, I just haven't found a solution that makes sense, so I am hoping someone here can help me. I have a pretty simple project schedule sort of web page that lists a number of tasks & 4 dates associated with each task. (planned start, planned complete, actual start, actual complete. The page is built dynamically based on what is in a mysql database, and the dates listed are form fields, with the intent that a person with access can change any number of these dates. Each task has an id associated with it, so when i build the form, I name the form field <task_id>-<date type>. so, for example, for task id = 10 I have 4 related form fields: 10-planned_start 10-planned_complete 10-actual_start 10-actual_complete This basic pattern is repeated for all the tasks (up to 100 right now, but it could grow slightly). Once all the form fields have been updated, and the user clicks submit I want to update the data in the database with the appropriate data. So, my questions is: 1) How can I process this form, when I don't know what the names of the fields are going to be, and/or how many fields there are? 2) Is there a good way to identify only those fields that have changed and do updates on only those fields, or am I "stuck" updating all the records, even those where the dates have not changed from when the form was built?
Changing Stuff In A Form Field To A Variable
I want to be able to change stuff typed into some form fields into a value so I can upload to a mysql table, then have it displayed on another page. I'm just not sure how to transport the form text.
Extract Form Field Names When They're Not Known In Advance
I have a page with a form which has automatically generated fields, (which come from mysql column names). There could be any number of these fields, and I have no way of knowing exactly what they're called. But obviously I need to know their names, in order to extract their values on the submission page. They are either of the form c%status#, e%status# or t%status# % is a number between 1 and 13 (inclusive) # could be anything in the pattern 01, 02, 03, with no limit Eg: fields could be c2status03 and e4status07, but I don't know this in advance. These would be generated on the fly from mysql. But on the submission page I need to be able to generate the code $var1=$_POST['c2status'] and $var2=$_POST['e4status07'] Is there a way for me to somehow get these names so I can extract their values on the submission page? Or have I hit a dead end?
Mandatory Email Field? - Contact Form
I'd like to make a contact page for a website where the email field is mandatory. I've used Smarty to make the page, and at the moment it works fine and displays fine. The few code edits I've manually made don't appear to work. I'd like to redirect the user to an error page if they forget to include their return email address. Code:
Storing Longtext In Mysql Using Form Field
I have a form which has the following part defined: <tr> <td> Description</td> <td><textarea name="mydescription" cols="50" rows="5"> <?php echo $fields[mydescription]?></textarea></td> </tr> Now, when I enter in some sentences into the textarea, and do a submit, I then extract the value and insert into the mysql db. The field in the DB is defined as a longtext. The problem is that this seems to only work if my sentence has about 15 words (approx 2 rows). If I go beyond 15 words, it won't store it. I don't seem to be getting any errors output either. I was thinking that perhaps the form itself is causing the issue since when entering in the data, it does a wrap around. Note if I do 15 words or less, it is stored properly in the DB.
Prevent A Single Space In A Form Field
I am allowing the user to create a URL and I would like to prevent the form from processing if they type something like 'jake 12' How would I check for a space?
Single Quotes In Database Field Breaks Form?
<?php echo "<input type=text name='storename' value='$storename'>"; ?> I noticed that if $storename contains something like "Ma's Bakery", all that shows up in the field is "Ma". Do I really have to go through all my form fields and change them to <?php echo "<input type=text name='storename' value='".$storename."'>"; ?> Although I guess <?php echo "<input type=text name='storename' value="$storename">"; ?> would work, too.
Formatting The Contents Of A Text Area Form Field
On my site I get users to enter a load of information in a textarea box, however when i save this data to my mysql DB and then retrieve it, it comes out without all the formatting, like new paragraphs and new lines. Can anyone tell me how you can capture the data entered into such a field with all the formatting the user has entered like new paragraphs etc?
Repeat Form Field Based On $_POST Data
i have a script that sets up a second page with multiple select boxes. the first script has a hidden field for the ID number, and a text input field for quantity. the second part of the script has a foreach loop that gets the info that goes with the ID number and then creates the select box next to it. for the most part it's all working correctly, but i don't know how to get the submitted "quantity" to repeat that ID number (and everything else). here is the initial form: Code:
Show Stored Value For Form Field Type=file
I have a file-uploading form to uploads a .jpg file and stores its name in a table in my db as co_bannerfile. I'm trying to now write an update form so the user can update their .jpg file. I've successfully written a query to retrieve the stored file's name. How can I display the stored file's name so the user can see its name within the input TYPE="file" field and then decide to update it or not? The following doesn't display the stored file name. What do I have wrong? Code:
Populating SELECT Multiple Form Field And Inserting Into Db
I have an update form where I'm trying to populate a SELECT multiple field with a list of 48 categories, from tbl work_cat. And show, as SELECTED, the one or many choices that the user had previously selected from the 48 categories which are stored in tbl cat_relations as $relation_cat. Then allow the user to update their selections and update the database. But I can't get my form to work. First problem, I can't get the SELECT field on the form to show the categories, and then I don't know where to go from there. Below are my form page and my processing page. Code:
Force User To Enter Characters Into A Form Field?
I have a form that our visitors need to use to sign up for our newsletter... Country is a required field on this form.. and I have it set up for PHP to check and make sure some thing was entered but what I am finding is that lot of visitors are just putting in several spaces. I have it validating to make sure something was put it in and to make sure that it wasnt just one space.. but if they enter multiple spaces the form processes. Is there any way or built in function that anyone knows about that will make sure that characters are entered and just not a series of spaces? or will I have to look to javascript for that?
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.
How To Find Full Path Of A File Upload Field In A Form?
I need a way to find the full path of a file uploaded by file upload form box. $_FILES['file1']['name'] gives just file name. I have a file upload form and if the user submitted something wrong I want the page to go back and have the forms maintain its values (the full path to local file, e.g: "c:/docs/landscape.jpg"). Any way to do that? This is a more complex applications so using another upload tool is not an option.
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:
Insert/Remove Portion Of Query Depending On Form Field
I have a form that updates an employee's information including a password for that employee. The form has a password field and what I would like is if the admin leaves that field empty, the users password remains unchanged in the database... but if the admin enters text into the password field then that text should update the database as the employees new password. The problem is to do this I need to either insert or remove a portion of the sql query. (There's probably an easier way to do this that I'm not seeing at 5:30AM.) But I don't know how to store the query portion outside of the actual query and then insert it when needed. So let's say this is the basic query. This is what I want if the password FORM field is EMPTY: ....
|