direct acces to php file from a form

Author Message

ludo thomas

Monday 11 July 2005 8:31:38 am

hi all,

I'm lookig for a method to have a direct link to a php file from an email.

In my email I have a form and submit button that send a node ID.

I want to delete the object which I have the node ID.

In my case It is a newsletter unsubscription button in an email.

my php file is like:

$objectID = $node->attribute( 'contentobject_id' );
$node->remove();
$object =& eZContentObject::fetch( $objectID );
$object->purge();

 

My problem is:
<b>-where can I put my file.php?
-what is the right <form action=''>?
</b>
(form is in an send email)

thx a lot for your help.

David Eriksson

Tuesday 12 July 2005 12:49:35 am

You'll want to read up on Actions. I'm not sure how much documentation there is online, if you got the book it's explained ok there. But see what you can find, and if you need any more help, I'll try to reply.

/David

ludo thomas

Tuesday 12 July 2005 5:48:40 am

I dont have find anything, it's why I post this thread...

David Eriksson

Tuesday 12 July 2005 6:12:01 am

Hmm, yes, actions seems to be very much missing from the documentation.

If you have created any "create new object here" buttons in your templates, then you have already used actions. But now you will have to write your own action. This is a rather technical explanation, for more help you can try studying /kernel/content/action.php, as well as the html code for create object here forms and the like.

Start by creating an extension. In content.ini.append.php for the extension, add:

[ActionSettings]
ExtensionDirectories[]=extensionName

Then create file extensions/extensionName/actions/content_actionhandler.php. Here's an example of how it should look:

<?php

        function extensionName_ContentActionHandler(&$module, &$http, &$objectID) {

                if ($http->hasPostVariable("ActionRemoveSticky")) {

                        $object =& eZContentObject::fetch($objectID);
                        $object->remove(false, $_POST["NotisNodeID"]);

                }

                return;
        }

?>

This example actually does exactly what you want to, I believe. It simply deletes the node with the NodeID given through the post variable.

To call on your action, you then use a form. Method should be post, action should point to index.php/content/action, I believe, and the submitbutton should have the name attribute set to the name used in the code, in the example above this would be ActionRemoveSticky.

You should also have a hidden field, with name="ContentObjectID" and value, well, the object id of the object you want to affect.

To send the Node ID as well, simply add a new hidden field, with whatever name you want, and you can access it like I did above in the PHP code, using $_POST.

Good luck!

/David

ludo thomas

Tuesday 12 July 2005 7:37:39 am

thanks a lot, it seems to be right

ludo thomas

Tuesday 12 July 2005 9:41:47 am

it's not working fine.

perhaps could you help me:

what is: <b>$_POST["NotisNodeID"]</b>

is it the node_id to remove?
I have put in my code:
<b><input type='hidden' name='NotisNodeID' value='313' /></b>
(I need to delete the node 313)

I have too:
<b><input type='hidden' name='ContentObjectID' value='410' /></b>
(the object_id is 410)

is it in relation whith: &$objectID ?

I'm lost.

David Eriksson

Wednesday 13 July 2005 12:26:09 am

Yes, $_POST can be used to access any variables of your own, like I do with NotisNodeID. I'm sure there is some other way, built in eZ, but nothing I'm aware of, and this works, so... :)

&$objectID, which you use in your code as $objectID, is the ContentObjectID variable, yes.

You can try to simply echo the variables, to see that they have been set correctly.

You haven't mentioned this, but if your action is called ActionRemove, for example, then make sure that your submit button is:

<input type="submit" name="ActionRemove" value="whatever" />

, and your action should be called.

/David

David Jones

Thursday 28 September 2006 1:49:26 am

I want to do something which is along similar lines.

I have a drop down form on my site which contains a list of links to other pages.

I want to hit submit and go to the selected page.

I don't want to do this via JavaScript for accessibility reasons so PHP seems the obvious choice.

How do I define an action to do this?

Your help is very much appreciated.

Claudia Kosny

Thursday 28 September 2006 12:59:01 pm

Hi David

Hopefully someone tells you a better solution, but as I don't know about actions I would do it with a simple extension which redirects to the posted node_id or url.
The idea is like this:
The options in your dropdown box have either the node_id or the url of the target node as value. Your dropdownbox is part of a form which is submitted to a view in your extension. Your extension just fetches the posted data and makes a redirect to the specified node. I have not tried it but I think the redirecting code is just something like this (assuming you dropdownbox has the name 'target'):

$Module =& $Params['Module'];
$target = !empty($_POST['target']) ? $_POST['target'] : '2';

if(is_numeric($target))  // node id is posted
{
  $Module->redirectTo('/content/view/full/' . $node_id);
}
else  // url is posted
{
  $Module->redirectTo($url);
}

Please note that this is really basic and not tested at all.

As to how modules work in general, check the example at
http://ez.no/products/ez_publish/documentation/development/extensions/module/hello_world

If you would use the view names of the example your form would need to post to {'/mymodule/hello'|ezurl()} and the hello.php script file would contain the redirect code.

Greetings from Luxembourg

Claudia

David Jones

Friday 29 September 2006 2:09:04 am

Thanks, I think I'm close.

I had a few problems registering the extension but now those erros have gone away.

The problem is that I always get redirect back to the root.

I've commented out the line which set the node to 2 if nothing is set. and it still always redirects me to the root.

THis is the form I am generating.

form action="/jumpmenu/jump" method="post" name="CountrySelector">

	<select name="target">

		<option value="/uk">UK </option>	
	

		<option value="/usa">USA </option>	
	

		<option value="/germany__1">Germany </option>	
	

		
	</select>

<input type=submit />

</form>

Have I done something stupid?

jump.php looks like this

<?php
$Module =& $Params['Module'];


//$target = !empty($_POST['target']) ? $_POST['target'] : '2';


 if(is_numeric($target)) // node id is posted


{
 $Module->redirectTo('/content/view/full/' . $node_id);
}
else // url is posted

{
 $Module->redirectTo($url);
}
?>

module.php looks like this.

<?php

$Module = array( "name" => "jumpmenu" );



$ViewList = array();

$ViewList["jump"] = array( "script" => "jump.php");

?>

Any thoughts?

David Jones

Friday 29 September 2006 3:34:55 am

Not to worry,

I've sorted it. I had a typo.

Thanks very much for your help

Claudia Kosny

Friday 29 September 2006 1:36:53 pm

Hi David

Good that you sorted it out. I just realised now that I should have reread or better tried the example code I posted before actually posting it.
So if anyone reads this later on, $node_id and $url should have been $target, so the correct (but still untested...) code is:

$Module =& $Params['Module'];
$target = !empty($_POST['target']) ? $_POST['target'] : '2'; 
if(is_numeric($target)) // node id is posted
{
 $Module->redirectTo('/content/view/full/' . $target);
}
else // url is posted
{
 $Module->redirectTo($target);
}

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.