Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

CB actions - how to integrate mutiple type of action code ? order ? link between each section ?

9 years 2 weeks ago - 9 years 2 weeks ago #271888 by smalldragoon
Hi All,
with CB actions, you can add different type of section ( in my case code PHP, then javascript ).

Is there any link that we can make between each section ? ( means a PHP section, then javascript, then html, then PHP again ? )
Here is my exemple :

I want to run several actions at the login of the user ( so far, so good in php ! CB is just great ! )

Now, I want to run a javascript and keep on for the login process.

to start debugging, I created a separate file that works when I run it "outside CB action"
in short, the code is loading a javascript, generate a key and submit it thanks to a form to a php file. ( I made the php form not hidden for debug purposes ).
I submit by javascript automatically the form.

here is the code with comments :

<?php

/*********************************************************************************************************************************************************/
// create default Community Builder user profile instance
/*********************************************************************************************************************************************************/
Global $_CB_framework;

$myId = $_CB_framework->myId();
$cbUser =& CBuser::getInstance( $myId );

if ( ! $cbUser ) {
$cbUser =& CBuser::getInstance( null );
}

/*********************************************************************************************************************************************************/
// create default user profile instance
/*********************************************************************************************************************************************************/

$user = JFactory::getUser();

?>

then javascript

Code:
function display() { ldmo.ldmoform('ldmo_prefs'); } function onSubmitForm(event) { var url = document.getElementById('url').value; ldmo.generate(url, true, display); event.preventDefault(); return false; } function post(path, params, method) { method = method || "post"; // Set method to post by default if not specified. // The rest of this code assumes you are not using a library. // It can be made less wordy if you use one. var form = document.createElement("form"); form.setAttribute("method", method); form.setAttribute("action", path); for(var key in params) { if(params.hasOwnProperty(key)) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } } document.body.appendChild(form); form.submit(); }

then the form :
Code:
<form id="myform" action="#"> <div style="width: 550px; margin: 0 auto;"> <br /> <table id="Launch" cellpadding="0" cellspacing="0" class="body";"> <tr> <td style="width: 300px;"> </td> <td valign="middle" align="left"> <br /> <label>Resource URL:</label>&nbsp;<input type="text" id="url" /><br /> <br /> </td> </tr> <tr> <td colspan="2" align="center"> <!-- ################################################### --> <textarea cols="60" rows="20" id="ldmo_prefs" name="ldmo_prefs"></textarea> <!-- ################################################### --> <br /> <br /> [code type=javascript] onSubmitForm(event)
<p />


<br />
<br />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
</div>
</form>
[/code]
Then javascript again to submit it automatically
Code:
setTimeout(function(){ post ('./FN/writejsc.php', { myvar : ldmo_prefs.value} ); }, 4000);

I tried to "split" each section ( JS in line ) , then html wihtout succes

Thx
Last edit: 9 years 2 weeks ago by smalldragoon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48466
  • Thanks: 8280
  • Karma: 1443
9 years 2 weeks ago #271958 by krileon
If you've multiple code blocks in a single code action they'll run 1 after another in the order specified. They've no relation to one another beyond that. The only way to have an HTML form submit to an action is to submit to an actions direct URL, which is found under the Global tab of an action. If the Method is set to Javascript it takes the inline JS and adds it to the header.

If you need PHP, HTML, and JS all in 1 then use multiple code blocks or set method to PHP and have it return then use echos in your code, but please understand not all triggers even have an output. For example the after login trigger is during a PHP action with an immediate redirect so there's nothing to display and no way for JS to output to do anything during it.

I can't help you with your custom code, sorry.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum