Need help with php form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Need help with php form

Post by tlenker09 »

Need a little help. This is probably a noob mistake however I didn't code the website or make this form for it. The problem is that the php is being displayed within the form fields. Here's a bit of a snippet of the code. I understand why but how can I fix the problem. Is there an easy fix or should I go back and rewrite the form in php and echo out the html.

Code: Select all

<td><input name="first_name" type="text" class="fieldstyle cform_name<?= isset($errors['first_name']) ? ' error' : ''; ?>" id="first_name" value="<?= isset($_POST['first_name']) ? $_POST['first_name'] : ''; ?>" /></td>
								<td rowspan="2"><div class="cform_spacer"></div></td>
Basically it's visually showing the php because it was inserted into the value field.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Need help with php form

Post by twinedev »

Try changing the opening tag from <?= to be <?php echo

Not all servers allow short tags, which is what is being used in that code.

There are ways so that if you this in tons of places to change the PHP settings per site to let it use it (I think), however I don't know offhand what the setting is, I prefer to reprogram to modern ways rather than put a "patch" in place to keep it going.

-Greg
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

twinedev wrote:Try changing the opening tag from <?= to be <?php echo

Not all servers allow short tags, which is what is being used in that code.

There are ways so that if you this in tons of places to change the PHP settings per site to let it use it (I think), however I don't know offhand what the setting is, I prefer to reprogram to modern ways rather than put a "patch" in place to keep it going.

-Greg
This could just as well be the issue as it went from a linux hosted environment to IIS.
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

Just for reference the setting in php.ini is "short_open_tag=On". You have to make sure it's set to on, in my case (default install) it was set to off. I knew this was a noob mistake :) I should have known better.

Also for reference for IIS users. You must go under IIS > Application Pool > Select Application Pool > Click Recycle. This will reload PHP with the new settings.

Thanks twinedev!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help with php form

Post by Celauran »

That solves the wrong problem, IMO. Your code is still dependent upon Short Tags being enabled and, therefore, is not portable. A better solution would be to replace <? with <?php and <?= with <?php echo.
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

Celauran wrote:That solves the wrong problem, IMO. Your code is still dependent upon Short Tags being enabled and, therefore, is not portable. A better solution would be to replace <? with <?php and <?= with <?php echo.
Please read above, again this isn't my code and I wouldn't have written it this way. If the site this form resides within ever gets moved again its going to be rewritten properly. Also IMO short tags are perfectly acceptable and can easily be used if your PHP configuration is right. If a webhost doesn't support short tags or refuses to enable them within the PHP configuration it's time to find another webhost.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Need help with php form

Post by phphelpme »

I think what Celauran is trying to say here is that your code is not portable even though you did not write it yourself. But by giving instructions like you have done with IIS still does not solve the problem for anyone because again even if they have written their own code like yours above it will still have the same issues when becoming portable.

I dont agree with being lazy and if you are going to complete a job then do it right or dont waste your time. :)

I have to agree with Celauran 100% on this one.

Best wishes
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

phphelpme wrote:I think what Celauran is trying to say here is that your code is not portable even though you did not write it yourself. But by giving instructions like you have done with IIS still does not solve the problem for anyone because again even if they have written their own code like yours above it will still have the same issues when becoming portable.

I dont agree with being lazy and if you are going to complete a job then do it right or dont waste your time. :)

I have to agree with Celauran 100% on this one.

Best wishes
Wasting my time would be picking through all of the code and replacing all of the tags. Why would I do that to something that is never going to become portable? It's a dedicated PHP website. There's a difference laziness and working smart.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Need help with php form

Post by phphelpme »

hahahaha Then thats another noob mistake you just made because your software even as basic as Notepad can search the content and replace your code in a matter of seconds. :)

No offence ment by both my comments by the way. Its just best practise and as you say Smart Coding to make sure you have a portable (full tag) code because anything could go wrong with your server, host and you could have the need to move without even wanting too.

I think you contradict yourself when you say:
If the site this form resides within ever gets moved again its going to be rewritten properly.
Surely, you are agreeing that this code is not written appropriately and slating a server for not supporting short tags (which could be mistaken for trying to keep coding standards high) is not good practise anyway.

Best wishes
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

phphelpme wrote:hahahaha Then thats another noob mistake you just made because your software even as basic as Notepad can search the content and replace your code in a matter of seconds. :)

No offence ment by both my comments by the way. Its just best practise and as you say Smart Coding to make sure you have a portable (full tag) code because anything could go wrong with your server, host and you could have the need to move without even wanting too.

I think you contradict yourself when you say:
If the site this form resides within ever gets moved again its going to be rewritten properly.
Surely, you are agreeing that this code is not written appropriately and slating a server for not supporting short tags (which could be mistaken for trying to keep coding standards high) is not good practise anyway.

Best wishes
I understand. Programming isn't my job, it was just something that was thrown at me because it wasn't working and people knew that I have had some knowledge in various programming languages back in school. A quick fix was all that I was looking for. If they want it fixed properly they can contact the idiots that wrote the website.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Need help with php form

Post by phphelpme »

they can contact the idiots that wrote the website
Very well said. :)

Just as long as you know that I was certainly not having a go at all just making a point. I understand you wanted a quick fix and you did actually get one.

Unfortunately, when people find out that you are capable of completing or messing or figuring out certain jobs and duties then you tend to be thrown into the deep end.

Take me for instance, I program for a living but I am also a fully qualified joiner, testing engineer, musician and manager... lol So when people find out I can do such things as joinery I get roped into the deep end. lol

The best bet is KEEP IT SECRET unlike I just did... lol

I am glad you got your fix. :)

Best wishes
tlenker09
Forum Newbie
Posts: 7
Joined: Mon Aug 22, 2011 2:59 pm

Re: Need help with php form

Post by tlenker09 »

Thanks again everyone for your help! Not a bad forum to come to for a google find ;) Thought I would get trolled out of here.
Post Reply