Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-09-01 05:18:10

dreamer
Member
Registered: 2007-06-08
Posts: 242

Inserting php into code

Hi TXPers. I was trying to include some php into my form and used the <txp:php></txp:php> code but I am getting an error for the taghandler as indicated on my site here; http://txpshadow.apatalk.com/services/welcome-to-your-site#

I looked up that file and the first line is simply; <?php

I’m not sure what to make of this and how to fix? Total noob at php

Offline

#2 2011-09-01 05:37:25

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Inserting php into code

Unless you have actually altered one of the core PHP scripts or a plugin that is active the line :
Parse error: syntax error, unexpected '<' in /nfs/c02/h11/mnt/41882/domains/txpshadow.apatalk.com/html/textpattern/publish/taghandlers.php(3741) : eval()'d code on line 2
is likely telling you that there is an error in your PHP code contained within the script’s Textpattern PHP tag set. These returned error codes are not always able to pin down exactly where an error took place if it was called from a template that was rendering within a call to a taghandlers function.

Offline

#3 2011-09-01 05:58:23

dreamer
Member
Registered: 2007-06-08
Posts: 242

Re: Inserting php into code

I didn’t modify the files. If it can’t pin down the issue, then what should I do?

Offline

#4 2011-09-01 07:30:04

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Inserting php into code

dreamer wrote:

I didn’t modify the files. If it can’t pin down the issue, then what should I do?

You could post the PHP code you used in your form, so that we can take look at it. Unfortunately we can not help you without knowing specifics, other than saying that there is a mistake in the PHP code.

Offline

#5 2011-09-01 09:59:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Inserting php into code

A wild guess: if you are inserting a php script inside of txp:php tags you can omit the opening and closing php tags in your script as the txp:php takes its place, e.g. if your code looks like this

<txp:php><?php ... actual code here ...  ?></txp:php>

change it to to read

<txp:php> ... actual code here ... </txp:php>

Maybe that helps?


TXP Builders – finely-crafted code, design and txp

Offline

#6 2011-09-01 17:16:37

dreamer
Member
Registered: 2007-06-08
Posts: 242

Re: Inserting php into code

Jakob- I managed to get rid of the error at the top with your suggestion. Still having issues with the errror in the footer though. Here is the form code for that area;


<div id="form">	<!-- BEGIN CONTACT FORM CONTAINER-->
<div id="middle">
<!-- <img class="ultimate" src="contact_lib/style/img/ultimate.png"> -->
	<!-- <div class="midle_border"> -->
		<!-- <h2>AJAX Form.</h2> -->
		<?
		/*
		The below PHP lines check if AddThis is enabled
		or disabled in the configuration file contact_lib/config.php.
		If it is enabled the AddThis feature will be added to the Contact Form.
		*/
		if($addthis) {
		?>
		<!-- AddThis Button BEGIN -->
		<div class="addthis_toolbox addthis_default_style "><a class="addthis_counter addthis_pill_style"></a></div>
		<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e1ea9435d7dcee2"></script>
		<!-- AddThis Button END -->
		<?}?>
		<!-- <p class="formTitle">AJAX Form with reCAPTCHA, Uploadify, GeoLocation, Google Map and Social Share!</p> -->
		<form action="#" method="post" id="sendEmail" name="sendEmail">
				<div id="fields">
				<fieldset>
					<label for=nameFrom><span class="mandatory">* </span>Your Name:</label>
					<input type="text" name="nameFrom" id="nameFrom" value=""  class="textfield" autocomplete="off"/>
					<label for=phoneNum><span class="mandatory"> </span>Phone Number:</label>
					<input type="text" name="phoneNum" id="phoneNum" value="" class="textfield" autocomplete="off"/>
					<label for=emailFrom><span class="mandatory">* </span>Your Email:</label>
					<input type="text" name="emailFrom" id="emailFrom" value="" class="textfield" autocomplete="off"/>
					<?
						/*
						The below PHP lines check if GeoLocation is enabled
						or disabled in the configuration file contact_lib/config.php.
						If it is enabled the GeoLocation feature will be added to the Contact Form.
						*/
						if($location){
					?>
					<!-- GeoLocation BEGIN -->
					<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
					<script src="contact_lib/js/geolocation.js" type="text/javascript"></script>
					<article>
						<label for=location> Your Location:</label>
						<input type="text" name="location" id="location" value="" class="textfield" autocomplete="off"/>
						<div class="location_img"><img src="contact_lib/style/img/location.png"></div>
					</article>
					<!-- GeoLocation END -->
					<?}?>
					<label for=subject><span class="mandatory">* </span>Subject:</label>
					<input type="text" name="subject" id="subject" value="" class="textfield" autocomplete="off"/>
					<!--<div id="displayLater" style="display:none">-->
						<!-- BEGIN DISPLAY LATER -->
						<label for=message><span class="mandatory">* </span>Message:</label>
						<textarea name="message" id="message"><?= $_POST['message'];?></textarea>
					<?php 
/*
The below PHP lines check if Uploadify is enabled
or disabled in the configuration file contact_lib/config.php.
If it is enabled the Upload feature will be added to the Contact Form.
*/
if($uploadify) {
echo "<label for=file_upload>Have Files?</label><input id=\"file_upload\" name=\"file_upload\" type=\"file\" />";
}
/*
The below PHP lines check if reCAPTCHA is enabled
or disabled in the configuration file contact_lib/config.php.
If it is enabled the reCAPTCHA feature will be added to the Contact Form.
*/
if($reCAPTCHA) {
?>
					<!-- BEGIN reCAPTCHA -->
					<div id="recaptcha_widget" style="display:none">
						<div id="recaptcha_image"></div>
						<div class="reload_recaptcha"><a href="javascript:Recaptcha.reload()"><img src="contact_lib/style/img/recaptcha.png"></a></div>
						<label for=recaptcha_response_field>CAPTCHA: </label>
						<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" size="25" autocomplete="off"/>
						<?= $_POST['recaptcha_response_field'];?>
					</div>
					<?php 
echo recaptcha_get_html($publickey, $error);
}
?>
					<!-- END reCAPTCHA -->
					<input type="submit" value="Ok, Done." name="submit" id="submit" class="submit"/>
					<div id="success" style="display:none">Thank you! Email sent successfully.</div>
				</div>
				</fieldset>
			</div>
			<!-- END DISPLAY LATER -->
		</form>
	<!-- </div> -->
</div>
<!-- END CONTACT FORM CONTAINER -->

Offline

#7 2011-09-01 19:17:27

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 596
Website

Re: Inserting php into code

You will need to go through that footer code and replace every <? or <?php with <txp:php> and every ?> with </txp:php>.

Offline

#8 2011-09-01 19:28:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Inserting php into code

That code seems to dip in and out of php so all instances of <?php ... ?> or <? ... ?> need replacing and all <?= turning into an echo statement. A lot of the instances where php is being used could be replaced with txp-equivalent functions.

Make a backup of your page and grab and install a copy of adi_gps. Then try this alternative approach that uses txp:tags in place of many of the php elements in your code. With luck it may work, depending on how the rest of the form processing code is written:


<txp:hide>
  Retrieve all $_POST variables and put them in txp variables
</txp:hide>

<txp:adi_gps post="1" quiet="1" />

<txp:hide>
  Set your config variables here instead of in lib/config.php
  Set all variables including any settings you don't want. 
  They should be set as empty variables as follows:
  txp:variable name="settingname" value=""
</txp:hide>

<txp:variable name="addthis" value="yes" />
<txp:variable name="location" value="yes" />
<txp:variable name="uploadify" value="yes" />
<txp:variable name="reCAPTCHA" value="yes" />


<div id="form">	<!-- BEGIN CONTACT FORM CONTAINER-->
<div id="middle">
<!-- <img class="ultimate" src="contact_lib/style/img/ultimate.png"> -->
  <!-- <div class="midle_border"> -->
    <!-- <h2>AJAX Form.</h2> -->

    <txp:hide>
      Check if AddThis is enabled or disabled.
      If enabled, add the AddThis feature.
    </txp:hide>

    <txp:if_variable name="addthis" value="yes">

      <!-- AddThis Button BEGIN -->
      <div class="addthis_toolbox addthis_default_style "><a class="addthis_counter addthis_pill_style"></a></div>
      <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e1ea9435d7dcee2"></script>
      <!-- AddThis Button END -->

    </txp:if_variable>

    <!-- <p class="formTitle">AJAX Form with reCAPTCHA, Uploadify, GeoLocation, Google Map and Social Share!</p> -->
    <form action="#" method="post" id="sendEmail" name="sendEmail">
        <div id="fields">
        <fieldset>
          <label for=nameFrom><span class="mandatory">* </span>Your Name:</label>
          <input type="text" name="nameFrom" id="nameFrom" value=""  class="textfield" autocomplete="off"/>
          <label for=phoneNum><span class="mandatory"> </span>Phone Number:</label>
          <input type="text" name="phoneNum" id="phoneNum" value="" class="textfield" autocomplete="off"/>
          <label for=emailFrom><span class="mandatory">* </span>Your Email:</label>
          <input type="text" name="emailFrom" id="emailFrom" value="" class="textfield" autocomplete="off"/>

    <txp:hide>
      Check if GeoLocation is enabled or disabled.
      If enabled, add the GeoLocation feature.
    </txp:hide>

    <txp:if_variable name="location" value="yes">

          <!-- GeoLocation BEGIN -->
          <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
          <script src="contact_lib/js/geolocation.js" type="text/javascript"></script>
          <article>
            <label for=location> Your Location:</label>
            <input type="text" name="location" id="location" value="" class="textfield" autocomplete="off"/>
            <div class="location_img"><img src="contact_lib/style/img/location.png"></div>
          </article>
          <!-- GeoLocation END -->

    </txp:if_variable>

          <label for=subject><span class="mandatory">* </span>Subject:</label>
          <input type="text" name="subject" id="subject" value="" class="textfield" autocomplete="off"/>
          <!--<div id="displayLater" style="display:none">-->
            <!-- BEGIN DISPLAY LATER -->
            <label for=message><span class="mandatory">* </span>Message:</label>
            <textarea name="message" id="message"><txp:variable name="message" /></textarea>

    <txp:hide>
      Check if Uploadify is enabled or disabled.
      If enabled, add the Upload feature.
    </txp:hide>

    <txp:if_variable name="uploadify" value="yes">

          <label for=file_upload>Have Files?</label><input id="file_upload" name="file_upload" type="file" />

    </txp:if_variable>

    <txp:hide>
      Check if reCAPTCHA is enabled or disabled.
      If enabled, add the reCAPTCHA feature.
    </txp:hide>

    <txp:if_variable name="reCAPTCHA" value="yes">

          <!-- BEGIN reCAPTCHA -->
          <div id="recaptcha_widget" style="display:none">
            <div id="recaptcha_image"></div>
            <div class="reload_recaptcha"><a href="javascript:Recaptcha.reload()"><img src="contact_lib/style/img/recaptcha.png"></a></div>
            <label for=recaptcha_response_field>CAPTCHA: </label>
            <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" size="25" autocomplete="off"/>
            <txp:variable name="recaptcha_response_field" />
          </div>

          <txp:php>
            echo recaptcha_get_html($publickey, $error);
          </txp:php>

    </txp:if_variable>

          <!-- END reCAPTCHA -->
          <input type="submit" value="Ok, Done." name="submit" id="submit" class="submit"/>
          <div id="success" style="display:none">Thank you! Email sent successfully.</div>
        </div>
        </fieldset>
      </div>
      <!-- END DISPLAY LATER -->
    </form>
  <!-- </div> -->
</div>
<!-- END CONTACT FORM CONTAINER -->

Be sure to set your config variables at the top as you want them (I put “yes” in all of them but the comment in the txp:hide statement shows an example of how to do a “no”).

I can’t guarantee that it will work but maybe you are in luck!!


TXP Builders – finely-crafted code, design and txp

Offline

#9 2011-09-01 19:53:45

dreamer
Member
Registered: 2007-06-08
Posts: 242

Re: Inserting php into code

thanks maruchan. this helps alot.

quick question; Do lines of code like;

<?= $_POST['recaptcha_response_field'];?>

or

<?}?>

also need to be replaced by the txp:php tag?

I replaced the other blocks of php code and tried replacing the above but still get errors. I can repost my code once I get confirmation from you. Thanks

Last edited by dreamer (2011-09-01 19:56:21)

Offline

#10 2011-09-01 21:05:17

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Inserting php into code

yes and yes, but it probably won’t work, because of this
Look at what Jakob posted, that’s a nice solution (if it works).

Offline

#11 2011-09-02 03:45:32

dreamer
Member
Registered: 2007-06-08
Posts: 242

Re: Inserting php into code

bah. still doesn’t work :( i think i’ll just nix the contact form in the footer and create a simple php page and the form in there instead.

Offline

#12 2011-09-03 09:05:57

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Inserting php into code

Or you could repost the code you have now and the errors it generates, so we can try to help you.

Offline

Board footer

Powered by FluxBB