How to add some PHP code inside a web page

General questions about CMSimple
Post Reply
mobak
Posts: 3
Joined: Sat Nov 02, 2013 6:52 pm

How to add some PHP code inside a web page

Post by mobak » Sat Nov 02, 2013 7:00 pm

Hi,

I want to create my own form page with POST & GET

1/ How to implement some PHP code inside the page ('ie'):

Code: Select all

<?php
if ($etat!="ok"){
if ($etat=="erreur"){
echo "<p><strong>".$erreur."</strong></p>\n";
}
[...]
?>
2/ And how to implement mixed HTML & PHP ('ie'):

Code: Select all

<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo SID; ?>">
<p><label for="email_expediteur">Votre adresse e-mail (obligatoire):</label><br />
<input type="text" size="40" name="email_expediteur" id="email_expediteur" value="<?php
if (!empty($_POST["email_expediteur"])) {
// l'adresse email de l'expéditeur a été saisie: la réafficher
echo htmlspecialchars($_POST["email_expediteur"],ENT_QUOTES);
}
?>" />


It seem i can't include directly this code, even i use the #CMSimple # syntaxe

Anyone have an idea ?
hx

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to add some PHP code inside a web page

Post by cmb » Sat Nov 02, 2013 7:27 pm

mobak wrote:It seem i can't include directly this code, even i use the #CMSimple # syntaxe
Indeed, you can't. Using PHP tags (<?php ...?>) is not possible at all, and using #CMSimple ...# doesn't allow output to be sent (for instance, with echo).

The cleanest solution is to write a function and put it to cmsimple/userfuncs.php; than you can call the function with the plugin call {{{PLUGIN:my_function();}}}. Note, that the function has to return its output instead of echoing it directly (you may use PHP's output buffering to simplify this), and that all global variables will have to be "declared" as such (global).

The simplest solution is to put the PHP resp. PHTML in a separate files, and to include it them with CMSimple scripting:

Code: Select all

#CMSimple include('path/of/file.php');#
mobak wrote:I want to create my own form page with POST & GET
GET forms that target the same page are not possible with any current version of CMSimple(_XH). This feature will be made available in CMSimple_XH 1.6.
mobak wrote:<?php echo $_SERVER["PHP_SELF"]; ?>
This would allow for XSS, by the way. You should at least use htmlspecialchars() here. For CMSimple it's quite common to use the following instead:

Code: Select all

<?php echo $sn. '?' . $su;?>
Christoph M. Becker – Plugins for CMSimple_XH

mobak
Posts: 3
Joined: Sat Nov 02, 2013 6:52 pm

Re: How to add some PHP code inside a web page

Post by mobak » Sat Nov 02, 2013 7:43 pm

Thx to answer me so quickly


Damned, it's terrible we can't use php code as in hml page.

I only want use a form page where people can send a file in the mail content.
I don't see any plugin doing that. We can send mail, but not with joined files.
I've try AdvancedForm Pulgin but we cant join files too.

It's so bad because it's easy to do that in html/php, don't you?

Have you an idea to add this feature?

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: How to add some PHP code inside a web page

Post by Tata » Sat Nov 02, 2013 7:51 pm

mobak wrote:It's so bad because it's easy to do that in html/php...
The plugin is exactly what you need. Using your own PHP in webpages may be a serious question of security.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

mobak
Posts: 3
Joined: Sat Nov 02, 2013 6:52 pm

Re: How to add some PHP code inside a web page

Post by mobak » Sat Nov 02, 2013 8:26 pm

ok, but there's no existing form plugin with join files possibility ?

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: How to add some PHP code inside a web page

Post by Tata » Sat Nov 02, 2013 9:38 pm

Download the latest version from http://3-magi.net/?CMSimple_XH/Advancedform_XH
It is able to attach files to an email. Read about settings and limits in delivered help.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to add some PHP code inside a web page

Post by cmb » Sun Nov 03, 2013 2:39 pm

mobak wrote:I only want use a form page where people can send a file in the mail content.
I don't see any plugin doing that. We can send mail, but not with joined files.
I've try AdvancedForm Pulgin but we cant join files too.
I'm not sure what you mean by "join files"--if you want to add attachments to the email, that is possible with Advancedform_XH, as Tata already pointed out (see the "Contact" form demo). However, it is not possible to let the user attach an arbitrary amount of files, resp. to join multiple files in a single attached archive file.

If you need more flexibility, you may have a look at Form Mailer. Another option is to have the mail form code in a separate file and to embed it on the page via an IFRAME. To resize the IFRAME automatically, you can use the Wrapper plugin or MagicFrames.
mobak wrote:It's so bad because it's easy to do that in html/php, don't you?
A simple mail form is easy to do with PHP, but there are quite some pitfalls which are easily overlooked. See cmsimple/mailform.php which doesn't even handle email attachments, but is nonetheless quite some code--putting all this inline on a CMSimple page might be rather distracting. Personally, I would prefer to keep anything but 1-liners in separate files, even if it was possible to add it on a CMSimple page directly.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply