[SOLVED] php forms displaying VALUE in the text boxes on new server, but not on old one
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In a nutshell Register_Global directive was on which automatically assigned your form values to variables when submitted by default. Since this directive is now depreciated your variables are not automatically defined. This is why your script does not work.
However, if php recognised $work as a not defined variable it should of displayed nothing instead of "$work" There could be a syntax error in your old code that is now causing problems with the current php version. Form values are now available using $_POST['xxxx'] or $_REQUEST['xxxx'].
OK. Now not being a php programmer, are there syntax checkers out there I can run my file through? I did the command line php check -l, and it didn't report any errors.
but for the other suggestion, do I just change that in my if ($send != "no") section? or do I change that every spot there's a $work for example? I think just in that if section, but want to make sure.
Actually, just tried to run it after my <? to <?php change, and that eliminated all the garbage from the text boxes! so I guess that question is void now. but when I click the submit button, it just clears all the forms out and I don't get the email.
I'm still confused on where I need to "Change all your form post variables i.e. $work to $_POST['work']" though? do I change it on the INPUT lines, where it's checking to make sure it's filled in, or where it's adding it into $msg? Sorry, feeling really dense on this part.
but wow, that first change made the form look identical to how it was on the old server, pretty amazing!
ok, I see where I have $PHP_SELF
<FORM METHOD=\"post\" ACTION=\"$PHP_SELF\">
so am I simply manually doing a find and replace of those 2 phrases to change it?
So sounds like every time I see a $employee for example that should become $_POST['employee']
I do see the errors with line numbers in error_log, but how to correct them (or how not to make things worse) i'm still struggling with. it complains of undefined variables PHP_SELF, employee, department, work, cell, home, pager, message, op.
Could someone show me what the line for PHP_SELF and maybe employee should look like, then i can try to fix the others myself?
You can use isset function to see of $op is set to remove that error. If not set then
you can define your form variables to equal "". This will not cause errors when you echo the form block string when first run. Then when you display errors you use the $_POST to get the form data.
If (!isset($op)) {
$message=""; // include all form variables
...
echo form_block;
}
if ($send=='no') {
$message=$_POST['message'];// assigns variables. include all form variables.
...
echo form_block;
}
$form_block = " <FORM METHOD=\"post\" ACTION=\"{$_SERVER["PHP_SELF"]}\"> <p><strong>Employee name: <font size=\"-1\"><em>(Exactly as it should be listed)</em></font> <font color=\"#FF0000\">**Required</font></strong><br> <INPUT TYPE=\"text\" NAME=\"employee\" VALUE=\"".myIsset("employee")."\" SIZE=\"75\" MAXLENGTH=\"100\"></p>
<p><strong>Department: <font size=\"-1\"><em>(Exactly as it should be listed)</em></font> <font color=\"#FF0000\">**Required</font></strong><br> <INPUT TYPE=\"text\" NAME=\"department\" VALUE=\"".myIsset("department")."\" SIZE=\"75\" MAXLENGTH=\"50\"></p>";
/* script continue */ ?>
Now, I think it's better to use single quotes for $form_block value imo
$form_block = ' <FORM METHOD="post" ACTION="'.$_SERVER['PHP_SELF'].'"> <p><strong>Employee name: <font size="-1"><em>(Exactly as it should be listed)</em></font> <font color="#FF0000">**Required</font></strong><br> <INPUT TYPE="text" NAME="employee" VALUE="'.myIsset('employee').'" SIZE="75" MAXLENGTH="100"></p>
<p><strong>Department: <font size="-1"><em>(Exactly as it should be listed)</em></font> <font color="#FF0000">**Required</font></strong><br> <INPUT TYPE="text" NAME="department" VALUE="'.myIsset('department').'" SIZE="75" MAXLENGTH="50"></p>';
/* script continue */
?>
Also myIsset() function should do more tests on posted variables to sanitize user inputs
<?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = ""; $name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } }
if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } }
if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } }
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.