Get simple CMS plugin - javascript

I am currently trying to modify a plugin that was made for get simple cms. The plugin is called "pages with comments". The reason I am posting here is because the topic for the plugin in the forums looks to be dead. Here is the link to the plugin I am currently using. https://mega.co.nz/#!pVcRnTiI!N0SyhLXrPbE1vFH3dNBaqO0zznETDD--QQpWp0c1EJoI have modified it but so you can see what code I am working with I am uploading it as a zip. My question is how do I make a a field required so when users submit the comment there has to be something in it. Either that or make that field a drop down.
Thanks
if ($capt =='Y'){
echo '<div id="captch"> ';
echo '<img alt="" class="capt" id="captcha'.$imfin.'" src="'.$siteurl.'plugins/pages_comments/img_cpt.php?url='.GSPLUGINPATH.'pages_comments/" />';
echo '<input type="button" value="'.$i18n['reload'].'" onClick="javascript:rec_cpt("captcha'.$imfin.'","'.$siteurl.'plugins/pages_comments/img_cpt.php?url='.GSPLUGINPATH.'pages_comments/")" /> <span class="msgavs">'.$i18n['rl'].'</span>';
echo '</div>';
echo '<div class="cap_input">';
echo '<input type="text" value="" name="guest[pot]" /><span>'.$i18n['Cpt'].'('.$i18n['Rf'].']'.'</span>';
echo '</div>';
}
echo '<div class="submit">';
echo '<input type="submit" value="'.$i18n['Ev'].'" name="guest-submit" />';
echo '</div>';

if (empty($_POST["field_name"])) {
$FieldErr = "FIELD is required"; //or any other error message
} else {
// code for submitting;
}
// you can dispaly the error message using echo $FeildErr beside your field area

Related

Can the JS Prepend statement edit pre-defined html?

I define my html by setting it equal to a variable i am echoing, just for the sake of keeping my php page dynamic, however i am trying to append another input div onto my text area once a button is clicked via a javascript statement. In terms of syntax i cant seem to find any errors, is this just not allowed?
this is the code for my comment area,
$comment_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" onfocus="showBtnDiv()" placeholder="What's new with you '.$u.'?"></textarea>';
$comment_ui .= '<div id="uploadDisplay_SP"></div>';
$comment_ui .= '<div id="btns_SP" class="hiddenStuff">';
$comment_ui .= '<form action=""><input id="gendercheck" type="checkbox" name="male" onclick="gendertoggle()">male</form>';
$comment_ui .= '<img src="images/topic.JPG" id="triggerTopic" class="triggerBtn" onclick="showtitleDiv" width="137" height="22" title="Add a title" />';
$comment_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'c\',\''.$u.'\',\'statustext\',\''.$male.'\',\'title\')">Post</button>';
$comment_ui .= '<img src="images/camera.JPG" id="triggerBtn_SP" class="triggerBtn" onclick="triggerUpload(event, \'fu_SP\')" width="137" height="22" title="Upload A Photo" />';
$status_ui .= '</div>';
notice i included an image icon for adding a topic to a comment that on click calls this function
function showtitleDiv(){
_("statustext").prepend('<input id="title" onkeyup="statusMax(this,30)" placeholder="Topic headline..."><br />');
/*_("triggerTopic").style.display = "block";*/
}
and i echo the $comment_ui in the body of my document, everything shows, and the comments work, its just the showtitleDiv function isnt working
the javascipt console doesnt show any errors, is the syntax wrong? I appreciate any and all of your expertise!

JQuery/javascript doubleclick=do something on each div from foreach() php

I have this PHP file:
foreach($allfiles as $file) {
echo '<div class="file" id="file' . $file->id . '">';
echo '<div id="checkbox"><img src="images/delete.png" width="15" height="15"></img></div>';
echo '<div id="filename">'. $file->name . '</div>';
echo '<div id="size">| '. $file->size . ' </div>';
echo '<div id="created">'. $file->created . '</div>';
echo '<div id="download"><img src="images/download.png" width="18" height="18"></img></div>';
echo '</div>';
?>
<script>
var id = <?php echo $file->id; ?>
</script>
<?php
}
and this JS file
$('#file' + id).dblclick(function() {
alert(1);
});
What I'm trying to do is that when div "file" + the file id is clicked, it will alert "1" (or open the file).
The problem is that now it only alerts 1 when I doubleclick the last div I have, while it is supposed to be done on all of them.
Is there a solution like foreach div called file + something do ? when doubleclicked.
Sorry if this was very unclear :D
You can use data-* prefixed custom attribute like
echo '<div class="file" data-id="' . $file->id . '">';
Bind your event using the common class and then fetch data-idusing .data()
$('.file').on('dblclick', function() {
alert($(this).data('id'));
});

javascript location.replace doesn't work

I have this code:
<?php
include 'theme.php';
css();
if($_POST['wget-send'])
{
$formdir=$_POST['dir'];
$formlink=$_POST['link'];
$filelink = fopen('/root/wget/wget-download-link.txt',a);
$filedir = fopen('/root/wget/wget-dir.txt',w);
fwrite($filedir, $formdir);
/*
fwrite($filelink, $formlink."\n");
exec('touch /root/wget/wget-download-link.txt',$out);
exec('echo "'.$dir.'" > /root/wget/wget-dir.txt',$out);
*/
exec('echo "'.$formlink.'" > /root/wget/wget-download-link.txt');
exit();
}
echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Send" id="WgetID"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">
function LinkAdded()
{
alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
location.replace("wget_log.php");
}
</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>
the alert part works it gives me a pop up but after the pop up, it just gives me a blank page. How do I make the location.replace("wget_log.php"); work?
stackoverflow keeps telling me that I should add more details on my post but I think that's all the details I can give.
You need to prevent the default action of submitting the form by returning false from the click handler
echo '<input type="submit" onclick="LinkAdded(); return false;" name="wget-send" value="Send" id="WgetID"/>';

form will not submit in innerHTML

I'm trying to get a form to submit with javascript in innerHTML, and the submit button just doesn't work. How do I make the form submit with innerHTML? The form works perfectly when it's in the body, but I need it in the function because I need the picdata data[1].
function photoShowcase(picdata){
var data = picdata.split("|");
_("picbox").style.display = "block";
_("picbox").innerHTML += '<div id="contain" style="background: url(\'user/<?php echo $u; ?>/'+data[1]+'\') center no-repeat rgba(0,0,0,.8);">';
if("<?php echo $isOwner ?>" == "yes"){
_("picbox").innerHTML += '<div id="deletelink">';
_("picbox").innerHTML += '<form method="POST" action="php_parsers/change_image.php" name="ChangeImage">';
_("picbox").innerHTML += '<input type="hidden" value="'+data[1]+'" name="file_name" />';
_("picbox").innerHTML += '<input type="submit" value="Set as Profile Picture" name="SetImage" />';
_("picbox").innerHTML += '</form>';
_("picbox").innerHTML += 'Delete Photo';
_("picbox").innerHTML += '</div>';
}
_("picbox").innerHTML += '</div>';
}
There is some points:
1/ Where is your PHP code?
2/ Where did You call the function? here is the function without any call... You have to call the function with right argument to work..
3/ You used (( += )) for first innerHTML...? why is that??? have you used this command before?
I think your answer is in this 3 point.
for more help, please make a jsfiddle...
In your code you are inserting incomplete html fragments and this is likely to cause the issue.
I would recommend to store the innerHTML in a variable and only append it to the document after it contains all the required closing tags:
var htmlString = '<div id="contain" style="background: url(\'user/<?php echo $u; ?>/'+data[1]+'\') center no-repeat rgba(0,0,0,.8);">';
//...
_("picbox").innerHTML += htmlString;

How to turn a hidden type input into a checkbox type input?

This might sound stupid, but I need something like this. I have displayed, say, 10 skills on the webpage, each of which is a hidden input of a form.
At the bottom there is an 'EDIT' button.
On clicking that, I want checkboxes to appear next to each skillName so that the user can check/uncheck them and then submit the form.
my php code snippet right now is something like this:
<?php echo '<span id="skillSet">';
for($x=0;$x<count($userSkills);$x++)
echo '<div class="skillName"><input type="hidden" name="skill[]" value="' . $userSkills[$x] . '" title="Click to select">' . $userSkills[$x] . "</div>";
echo '</span>'; ?>
<input type="button" value="Edit" onClick="someFunction()">
What can i put instead of some function to achieve the required result?
Also, if there is any other way I can implement the editing thing, please do tell.
Thanks in advance!
Give all inputs the class input_skill, like this:
echo '<div class="skillName"><input type="hidden" name="skill[]" value="' . $userSkills[$x] . '" title="Click to select" class="input_skill">' . $userSkills[$x] . "</div>";
Then use this function to change their types:
<script type="text/javascript">
function ShowSkillCheckboxes() {
var skills = document.getElementsByClassName("input_skill");
for(var i=0; i<skills.length; i++)
skills[i].setAttribute("type","checkbox");
}
</script>
Keep in mind that the special checked value which the elements get by becoming checkboxes will vanish once you transform the checkboxes back into hidden type inputs. Besides: hidden inputs do not display at all on the webpage. You can say they have 0x0 px dimensions. This means that upon clicking the Edit button, those checkboxes will pop out and extent your layout.
Thanks for the input guys, but I found a way around it.
And apologies as well, since I ended up NOT using the hidden input at all.
If any of you are interested, this function should do the trick:
function editSkills()
{
var skills = document.getElementsByClassName("skillName");
for(var i=0;i<skills.length;i++)
{
var value = skills[i].innerHTML;
skills[i].innerHTML = '<input type="checkbox" checked name="skill[]" value="' + value + '" title="Toggle Selection">' + value;
}
document.getElementById('EditOrApply').innerHTML='<input type="submit" value="Apply Changes">';
}
That final line converts the 'Edit' to the 'Submit' button for the form.
the -1 he gave me is the usual way to act of greedy and unfair people. Probably he did it like the users before have done with him (have taken advantage of his low reputation). Anyway I want to underline this not for revenge,but to let the users to valutate the answers in an fair way
Something like this? jsfiddle
$userSkills = array('pasta','maccheroni','pizza');
echo '<span id="skillSet">';
for($x=0;$x<count($userSkills);$x++)
echo '<div class="skillName"><input type="hidden" name="skill[]" value="' . $userSkills[$x] . '" title="Click to select">' . $userSkills[$x] . "</div>";
echo '</span>'; ?>
<input type="button" value="Edit" onClick="$('input:hidden').attr('type','checkbox');">
you need jquery (<script src="http://code.jquery.com/jquery-1.9.1.js"></script>)
FULL JAVASCRIPT
<input type="button" value="Edit" onClick="show(document.getElementsByTagName('input'))">
<script>
function show(val){
for(i=0;i<val.length-1;i++){
if(val[i].type=='hidden'){
val[i].type='checkbox';
}
}
}
</script>

Categories