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
Related
I have a script that I downloaded and want to add an href="#" to it but it's interfering with the form on the page. The form is triggered by a button, not sure of that matters. I tested my href outside the form but it still refreshes the page once before it works. Here is the code.
<form method="POST" action="/profile/save_profile_setting">
Update My Location
</form>
<button class="btn" type="submit" name="action" ><span><?php echo __( 'Save' );?></span></button>
My href just passes the id to run ajax to find a location, it's always worked but now the two aren't playing well together. I have the same href on a different page by itself and it works fine.
Thanks for any help.
I didn't understand what is your actual query. I understood roughly of your query. My understanding for your question is that: with tag, you want to execute ajax call and with button, you want to perform form action. Based on this assumption:
(1) If you want to avoid page refresh with tag, you need to do as follows:
Update My Location
Now, you can easily perform ajax with tag.
(2) To perform button action with form, you need to add button inside form instead of outside the form.
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
I'm building a website in which the user can create articles with multiple images.
I would like to let the users while editing the form to can delete some image that they want. So I want to have in my form the main submit button that execute the function that store all details of article but also to I have another submit button that execute the function that delete the image.
How can I do that?
Thank you so much for your attention and participation.
If I got you right, you want 1 FORM, 2 SUBMIT buttons, and based on which one you press, do a different action? It is possible to do this, but not very practical.
To do it, create 2 submit buttons with each a value. I.e.:
<input type="submit" name="mysubmit" value="delete image" />
<input type="submit" name="mysubmit" value="send the form" />
when doing this, your post/get data will contain one item names mysubmit with the value, so you know which button was pressed, and you can do an action based on this.
However, when you submit a form by pressing a submit button, you do send the whole thing to your server, and have a page refresh. I usually prefer to use Ajax for the simple operation. For example, I would remove the delete submit button and replace it a simple button. When pressed, send an Ajax call to tell the server to delete the image, and use DOM to delete the image in the browser DOM tree (usually jQuery). Note that you can also use Ajax to post the form, nicer interface, and no page refresh.
I have a form to submit details to database, after processing the POST on the action page i have another form to upload a photo very closely related to the info provided on the previous form, in fact the image path is stored on the same record in the database, instead of having two pages / two steps process, is it possible to have them both on the same form?
i know that nesting forms is not possible, at the same time uploading the file requires a form.
Using anchors and GET method is not acceptable in my application for the info is too sensitive to be revealed in URL
is there a way to workaround this?
thanks in advance
You could use
either session variables (to temporarily store the first step of the form)
or javascript to cycle through steps without refreshing the page
How about using 2 fieldsets?
<form action="?">
<fieldset>
//input fields
<input type="button" value="Next" id="btnNext">
</fieldset>
<fieldset>
//foto input field
<input type="button" value="Submit">
</fieldset>
</form>
Then in JS (with jQuery):
$("fieldset").eq(1).hide();
$("#btnNext").click(function(e){
e.preventDefault();
$("fieldset").eq(0).hide();
$("fieldset").eq(1).show();
});
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" />
...