Linking to a text field - php

I am trying to get people that are not logged in to log in by linking them to the log in fields in the sidebar.
So far I managed to accomplish this:
<?php comment_form(array(must_log_in => sprintf(__('You must be logged in to comment.')))); ?>
So I am using the Login with AJAX widget, or I could just place the plugin's template tag in there which is <?php login_with_ajax() ?>. Right before the widget I have placed <a name="reg"></a>, so when they click the link to log in they get to where the log in form is, but they are not placed in the username field. Is there a way (I doubt it) where I can place the focus in the username field? That is to have a blinking cursor in there?
"It is not possible" is also an acceptable answer, so I can move onto my next problem.

Assuming something like <input type="text" id="username">, you could use
document.getElementById("username").focus();
in JavaScript.

Related

Scroll to a point in a wordpress designed website

I am working on a website which is designed in wordpress. In my one page i have a form included which is
[contact-form-7 id="144" title="Contact Form"]
No from one page i want to redirect to this particular id, for which i am writing
<href="http:my_url/contact#144"> which is not working
i have also tried
<href="http:my_url/contact.php#144"> but giving me page not found 404 error.
So what i am doing wrong that i am not able to detect.
That ID is only the ID of the form you're pulling in, referenced internally by the plugin - it isn't output on the element itself. If you go into the inspector, it'll be something like wpcf7-f482-p481-o1, only with different letters/numbers after wpcf7. If you want to make a prettier link, just wrap the embed code in a div with an ID of your choosing and use that on the anchor.
You can't do this on a contact form 7 id.
Try:
<div id="cForm">
[contact-form-7 id="144" title="Contact Form"]
</div>
Then link to with Contact form

echo'ing out a jquery .remove() function?

Im creating a blogging system with on page post editing.
If a user is logged in, and they created the blog post then they can see an edit button.
Currently, the edit button is always displayed but is set a display: none for non allowed users.
This works... but ofcourse some one can just change the styling to block with inspector on their browser and viola it works!
I have thought about this and when processing an update in my /updatepost.php page i do another check to see if the user has appropriate access before updating the database.
I dont want however the user to even be able to get this far.
My next idea was instead of setting the button to display none, i would echo a script to remove the button.
I tried e.g.:
if (!isset($userid)) {
echo '<script> $("#editbutton").remove(); </script>';
}
but that doesnt seem to work.
I could go down the route of creating spans with the user id and the post owner id, then check the value .html() and then check if they match etc. But i prefer my first method.
Any ideas as to where my idea is going wrong?
This should be solved in php, no JavaScript required. Only print the edit button if the user can edit the post.
You are not using it in a document ready. That is probably the root issue. This is getting executed before your page is ready.
Just the opposite, only write out the edit button (and other associated elements) if the user has sufficient privileges.
if (isset($userid)) {
echo '<button id="editbutton">Edit</button>';
}
if (isset($userid)) {
// show edit button with no need for Javascript
}

contenteditable for inline editing with ckEditor

I'm creating an inline CMS using ckeditor. The idea is:
Client logs into admin area
Login beings a session
Client is directed to pages on their website where they can edit predefined regions
The regions are specified with the contenteditable attribute:
<div contenteditable="true">
safsdfdfsdfdfsdfsdfds
</div>
Since a session is created when the client logs in, I've written some PHP that knows to enable ckEditor and all the CMS functionality if the client is logged in.
The issue I have, is when not logged in, contenteditable="true" on divs still allows you to edit them without a WYSIWYG as the default behaviour for the browser. Obviously this is no good. How do I stop users being able to edit the page?
You could setup the divs like that:
<div data-contenteditable="true">
And have a JavaScript (if in admin mode) go over all divs (document.getElementsByTagName("div")) and if they have data-contenteditable set the real contenteditable.
Otherwise let the server only include contenteditable if in admin mode
In PHP:
Create first a function that returns true if the user is logged in, then, for each editable region (in your views):
<div<?php if (your_login_check_function()) echo ' contenteditable="true"'; ?>>Lorem ipsum</div>
It's a bit tedious but it should work.
Or in jQuery (as proposed by Moritz):
Add a data-contenteditable="true" to your editable nodes, then add a script to the end of the page when the user is logged in:
<script>$('[data-contenteditable]').attr('contenteditable', true);</script>

Sending information across pages PHP

i have an ajax / php feature of my site that pulls in information from a table every 20 seconds. The information is about hobbie's
It displays on the page the name of the person and their hobby. I have a second page that acts as an information source for that hobby. Currently the only way to access the second page is by entering your hobby into a form on the first page. How would i get it so that i could click on the hobby that is being displayed on the homepage and access an information page on the hobby.
To access the information it currently grabs the hobby from a POST command.
The table results are being displayed on the homepage via
echo $row['name']." is interested in ".$row['hobby'];
Could i some how pass the hobby name through to another page? I only know how to do it through form submits.
I don't think that sesssions are necessary for this.
Look at what information your form is sending. If you're making a GET request you can add that url to a link.
So on your home page you could have links like the one below instead of forms.
<a href="/hobbies/?name=remote+controlled+cars>Remote Controlled Cars</a>
So with the link it would no longer be using $_POST but $_GET instead.
Psudeo code for your homepage link below.
<a href="/hobbies/?name=<?php echo slugify($row['hobby']); ?>><?php echo $row['hobby']; ?></a>
Look into using PHP's sessions.
You can create an anchor tag that is generated from the data provided with a query tailing it to carry the data over, effectively creating a link pointing to the next step with additional information. The only problem, of course, is that this is exposed to the user which can be hijacked.
You can also, if you are using only form submits, create a <input type="hidden"> with a value/name of something you can use to navigate to the next page, if you so desire.

Creating a custom login instead of using the original login box

Lets say there is a php website that has a login boxes (password,username), can you create a login box in different page of your own that when you enter your login information it will let you log to that website? I mean is it possible? and using what language?
If anyone wants a link of the website I would be glad to post it. It is my university website actually.
This may help:
<b>User Name:</b></span></td>
<td width="60%"><span class="text10">
<script language="JavaScript1.2">
document.writeln("<input class=\"textform\" type=\"text\" name=\"user\" size=\"" + size + "\" tabindex=1 onFocus=\"hadFocus(true);\">");
</script>
Just copy the university site's login HTML into your page (everything in the <form> element, including the <form> element itself) and change the action so that it's fully qualified (i.e. if the action was /login.php change it to http://myuniversity.edu/login.php).
Then, you can mess around with the HTML and modify it however you like. The important things are that any inputs, selects, and textareas have the same name as they do on the university login form, and that the action is a full URL.
What you could try is to just view the code of the original login page, copy the HTML for the form, and try pasting that into your page.

Categories