xR34P3Rx
xR34P3Rx

Reputation: 395

Use <p> tag as input

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!

Upvotes: 0

Views: 2788

Answers (2)

MadeInDreams
MadeInDreams

Reputation: 2146

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

Upvotes: 0

James Paterson
James Paterson

Reputation: 2915

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>

Upvotes: 1

Related Questions