Use <p> tag as input - php

Im making a control panel for my site that will dynamically display posts made by the user logged in. How i have it planned in mind is the MySQL server has all posts made by all members in one table. When the control panel loads, a PHP script will run and query from that table all the posts made by the logged in user in the form of a table displaying the Title of the post, an Edit and Delete button.
My idea to get the Edit and Delete button working is to have each post display as a form. The issue i have is how to display the title of the post.
i dont want the title of the post (as a form) to be as an input field but rather have it be say <p value="My Post" name="mypost">My Post</p>. Then have the Edit button, when clicked, $_POST['mypost'] the <p> tag as if it were an input.
In example:
<form method="post" action="edit_post.php">
<p name="title" value="My Post">My Post</p>
<input type="submit" value="Edit"></input>
<input type="submit" formaction="delete_post.php" value="Delete"></input>
</form>
And for the mean time, just have edit_post.php echo the content/value of the <p>:
<?php
echo $_POST['mypost'];
?>
If i use a regular input field instead of the <p> tag, it works, of course. but as i said, i dont want to display the title of the post as an input field. Im not sure what the "professional" way of doing this is, im just coming up with an idea of my own.
Thanks in advance!

In short - You can't do this. Only input tags pass data through the form. As a workaround, you could use a hidden input:
<form method="post" action="edit_post.php">
<p>My Post</p>
<input name="title" type="hidden" value="My Post">
<input type="submit" value="Edit"></input>
<input type="submit" formaction="delete_post.php" value="Delete"></input>
</form>

I know where your getting but this is to much for what you want.
To get the content of <p>: And by the way it would be better to use one of the h1/h2/h3 tag instead since search engine will recognize it as being what it is, a title. But let's just call it an element.
With JavaScript you can get the content of an element using html() mostly used with JQuery. http://api.jquery.com/html/
And you are posting data. You probably want the Ajax with it so JQuery will deal with it easy. Quick search on Google should get you started with Jquery.
And Json is really nice and easy to use once you get a grasp.
But you can do that pretty much any way you want, You could just use CSS and hide all the borders and such and make it disabled so it would blend in or take a particular style.
Or the edit link could be a get instead of a post. processor_page.php?title="my_post_title"
And if you plan on going with JavaScript I recommend AngularJS

Related

advance search with php with pagination?

I have some users with some info like their countery_id, their education_id, their degree_id etc. and I want to fetch them based on this info in a page with pagination.
I know how to do this with $_GET but I want my URL to be clean and I want use $_POST for send users info and fetch them.
and for pagination I use get method like this , ?pg=1
The problem is when I send form and fetch users in first page, there is no problem but when I click for second page. I lose my $_POST variables and can't fetch second page result.
what is the best answer for this situation?
Make the next button to be actually part of a form that submits by post.
<form method="post" action="page.php?pg=2" id="myForm">
<input type="hidden" name="education_id" value="<?=$education_id;?>" />
<!-- and so on for the rest of the properties -->
<input type="submit" value="Next" />
</form>
or you do not want submit button, create the form and put a link like this one somewhere.
<a href="javascript:;" onclick='$("#myForm").submit()'> Next </a>
Edit: As you can see this solution is not elegant, but it will work. Using $_POST is not recommended, $_GET is better because of bookmarking, etc

Search Function/Quick Search: How to get HTML Input value to php $variable without $_POST or $_GET

I have a quick search tab at the top of my menubar. It has an input textbox (for the content to search for) and a button. When this user currently fills in box and clicks the button the user is brought to the actual search page.
On this search page, a more advanaced set of search filters is displayed at the top of the page (with a submit button) and then the results of the search would be displayed below.
What I want to do is display the results of the basic search (from any other page, using the menubar) upon the search page loading without the user having pressed the submit button on that page. This will hopefully save time for the user (maybe the advanced search wasn't needed). NOTE: The advanced filter textbox regarding what text to search for is autopopulated by the content from the basic search textbox when the basic search button is clicked and the user is brought to the search page.
However, since I am not pressing the submit button I can't use the $_POST["searchText"] as a parameter for my if condition (which only displays search results if the user entered text in the textbox) to display the search results. Instead I would much rather user something like:
!is_null(searchText.value)
But obviously this is incorrect syntax/doesn't exist. Does anyone have a suggested solution to get the content from the HTML Input searchText into a PHP $variable?
I don't quite follow why POST/GET could not be used. When the user is on page X and they enter a search value into the menubar, they would be taken to the search page with the search query passed via GET/POST.
It is really up to you to change your server-side logic to immediately perform the search on this query and show the results rather than show the more advanced search filter options (or to show the advanced options in addition to the search result). You don't need a second communication from the search page to the server to initiate the search functionality.
So on your advanced search page, you are looking at doing the following:
<input type='text' name='searchText' value='<?php echo (isset() ? htmlentities($_POST['searchText'], ENT_QUOTES) : ''; ?>' />
I think htmlentities is correct there, but I may be wrong.
The echo is actually a ternary. I believe isset() is probably the equivalent you are looking for. Basically, it checks if $_POST['searchText'] is set, and either echoes the contents of that, or nothing at all.
$_POST and $_GET are global variables, so you can get away with just checking them with isset(). However, for your own arrays, you need to check with array_key_exists('key', $array) before checking with isset($array['key']).
$_REQUEST["name"] Replaces both POST and GET
<form action="#" method="POST">
<input type="text" name="one">
<input type="submit" />
</form>
<form action="#" method="GET">
<input type="text" name="one">
<input type="submit" />
</form>
<?php
if(isset($_REQUEST["one"])){echo $_REQUEST["one"];}
?>

Is there a way to prevent the editing of HTML and CSS contents in a page using Firebug-like tools?

Is there a way to prevent the editing of HTML and CSS contents in a page using Firebug-like tools?
I found that some users are editing some values in hidden fields and some contents which written between a div or span tag for gaining some profits. They are doing mostly by editing with help of tools like firebug. Is there any way to identify such modifications? The problem here is that the values they are editing is generated when the page is compiled. The page is developed in PHP. The editing is done mostly in between the and tags.
Thanks in advance for the help.
There is no way to prevent users from changing the information that is submitted from their browser to your server. You do not have control over their browser.
To fix this problem, you must change the design of your server application so that sensitive information that users should not modify, is not sent to the browser and submitted back to you.
The following is a simple example. Suppose you have an online store and are implementing an "Order" button. Suppose you have a form like this:
<form action="/order">
<input type="hidden" name="description" value="Better Mousetrap">
<input type="hidden" name="price" value="15.00">
<input type="submit">
</form>
If you have a form like the above, the user could change the price value to whatever they want when submitting the form. That is probably not what you want. Instead, you could do something like:
<form action="/order">
<input type="hidden" name="item_id" value="1234">
<input type="submit">
</form>
Then, when this form is submitted, you look up item_id number 1234 in your database, and get the price from that. The only thing the user could change in this case is the item_id, which means they would get a different item than what they wanted.

Submit Contact form asynchronous and show Result in a Modal like fancy box using PHP

I have a simple Contact form and i have to submit it asynchronous and then i have to display result in a Modal like window more like Fancybox.
<form name='contactForm'>
<input type="text" name="Fname" />
<input type="text" name="Lname" />
<input type="submit" value="Send" />
</form>
I dont have experience of working in PHP still i can manage to submit form data asynchronous and display data in a div area but i am not sure how i can display the RESULT in a fancybox or something similar which will greyout the background and show the success message.
I also need to Validate form before i submit it.
I'm not going to write your application, but I'd tell you how I'd approach it:
Serialize the data and send it via an AJAX Request (using jQuery).
On success, use the fancybox plugin to display "Thank you for contacting us".
You can get jQuery here.
Fancybox and Docs are here.
Using AJAX and jQuery.
jQuery validation
Since you didn't really provide any detail on a specific question, this is the best I can really do. If you take the time to familiarize yourself with the Docs on each of these links, I am sure you will be able to pull this off very easily. From what you already have, the only thing left would be to just learn the Fancybox plugin, which can be invoked with 1 line of code.

What's the standard way to give a set of different clickable options all submitting the same form?

I have a PHP-generated page which is displaying some data about a set of films. The page is updated using POST. The form only shows films starting with a particular letter. I want to present a set of clickable options at the top of the screen, each of which is a letter. So if you click on "B" it submits the form and re-draws the page showing only films that start with B. (I know, Ajax would be a better way to do this, but I'm trying to get something done quickly).
Anyway, I know I can do this by having each link be a Javascript call which sets the value of a hidden field and then submits the form, or I could do it by having each letter be a button which has a particular value and submits the form directly, but neither of those strikes me as particularly elegant. Is there a standard way to do this? Am I missing something really obvious?
You can always create a number of submit buttons and give each a different name. Then you test to see which submit was pressed based on what is included in the POST array.
Please note that you can use the image input type in place of the submit input type so that you can substitute your own image, etc for your button.
I think you pretty much cover the options you have. I generally see it done with javascript and hrefs because people don't like to style real buttons.
Be aware that Internet Explorer (6/7?) doesn't POST a variable with the name of the button on an <input type="image"> - it only posts variables with name_x and name_y with the coordinates of where on the button was clicked.
You don't actually need to submit the form as you are not really using it.
Why not just a set of hyperlinks B
Use several different submit buttons, like this:
<input type="submit" name="letter" value="A" />
<input type="submit" name="letter" value="B" />
<input type="submit" name="letter" value="C" />
...

Categories