Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-09-30 21:02:13

helmz
Member
Registered: 2010-09-14
Posts: 65

Cant use php in default page??

Well, first of all, this morning i noticed i couldnt put any <?php tag why?
Secondly after cant use php code i tryed javascript, but its not running, does anyone know why?

<form method="post" onclick="ventana()" onsubmit="return checkCheckBox(this)" action="datadb.php">
<div class="accept">
<input type="checkbox" class="required" style="position: absolute; " value="acepto" name="legacy">
</div>
<SCRIPT language="JavaScript" type="text/javascript">
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert("Accept legacyy");
return false;
}else
return true;
}
</SCRIPT>

thanks

(added a space after bc. -Els)

Last edited by els (2010-09-30 21:19:01)

Offline

#2 2010-09-30 21:21:35

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Cant use php in default page??

Preferences > Advanced: Allow PHP in pages

Don’t know about the js. Maybe Firebug can tell you something?

Last edited by els (2010-09-30 21:22:29)

Offline

#3 2010-09-30 22:00:08

helmz
Member
Registered: 2010-09-14
Posts: 65

Re: Cant use php in default page??

ok done that, there i saw lots of errors like this:

txp_plugin: error: Table upgrade required. Please do “REPAIR TABLE `txp_plugin`” or dump/reload to fix it!,

what mean with REPAIR TABLE?

Offline

#4 2010-09-30 22:12:52

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Cant use php in default page??

You can do that in phpMyAdmin. You’ll probably find it in your host’s control panel under ‘Databases’ or something similar. Find your database and the repair function is under ‘Operations’ I think. You need to repair the table named txp_plugin.

Offline

#5 2010-10-04 08:21:18

helmz
Member
Registered: 2010-09-14
Posts: 65

Re: Cant use php in default page??

I still recieve an error if I use php code, and i activated it in advanced options

Offline

#6 2010-10-04 11:14:20

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Cant use php in default page??

Are you using txp:php tags? You can’t put PHP directly in templates.

<txp:php> 
// raw code goes here, do NOT use '<?php' and  '?>' tags 
echo 'This is how to use raw PHP in Txp';
</txp:php>

Code is topiary

Offline

#7 2010-10-05 08:54:14

helmz
Member
Registered: 2010-09-14
Posts: 65

Re: Cant use php in default page??

Ok, was using normal php tags.. thanks.

Do you know why isnt this working?(i mean the ‘alert’)

<txp:php> 
if (isset($_POST['legacy']))
{   $legacy = '1';
     $status = 'Accepted.';
    echo "
        <script language='JavaScript'>
        alert($status);
           //status is error content
        </script>";";
} else {
    $legacy = '0';
    $status = 'Error, checkbox not accepted. ';
    echo "
        <script language='JavaScript'>
        alert($status);
           //status is error content
        </script>";
}
</txp:php>

Offline

#8 2010-10-05 09:37:27

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

Re: Cant use php in default page??

helmz wrote:

Do you know why isnt this working?

  1. You have syntax errors in the PHP code. ";"; should be ";.
  2. Code has variables that do nothing. Why are those there, what should the code do?
  3. Your script tags are missing mandatory type attribute.

Offline

#9 2010-10-05 09:44:29

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Cant use php in default page??

Don’t forget script requires the type attribute. That’s not the problem here, though. Try:

<txp:php> 
if (isset($_POST['legacy']))
{   $legacy = '1';
     $status = '"Accepted."';
    echo "
        <script language='JavaScript'>
        alert($status);
           //status is error content
        </script>";
} else {
    $legacy = '0';
    $status = '"Error, checkbox not accepted."';
    echo "
        <script language='JavaScript'>
        alert($status);
           //status is error content
        </script>";
}
</txp:php>

That is, alert() needs the string to be quoted, so you need to include quote marks in the $status string. And the PHP didn’t parse because of the extra "; at the end of the first echo.


Code is topiary

Offline

#10 2010-10-05 09:52:47

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Cant use php in default page??

Another approach:

<txp:output_form form="alert">
    <txp:php>
        echo isset($_POST['legacy']) ? 'Accepted.' : 'Error, checkbox not accepted.';
    </txp:php>
</txp:output_form>

That goes in the page template. The form named “alert” looks like this:

<script type="text/javascript">
<!--
    alert('<txp:yield />');
-->
</script>

Edit: HTML-escaped script content

Last edited by jsoo (2010-10-05 09:55:21)


Code is topiary

Offline

#11 2010-10-05 09:56:19

helmz
Member
Registered: 2010-09-14
Posts: 65

Re: Cant use php in default page??

Oh, what a mistake . i feel so stupid sometimes, just a more question, how i can do to DONT go to next page when clicking submit if checkbox isnt true, cose just appears the page to send to db without anything and just with the alert box,

thanks in advance im so newbe and i realy appreciate this help from you, and im new too with txp so…what a mix :D..

Offline

#12 2010-10-05 10:50:38

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Cant use php in default page??


Code is topiary

Offline

Board footer

Powered by FluxBB