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> <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