so I have been building a small website with a content management system I have built using PHP and mysql. What I am trying to achieve is the user needs to be able to edit and delete the announcement posts they make, so I have been using $_GET to get the ID of the post that is to be edited/ deleted and chucked into a form which holds the code to do that.
Now, this is the code I have been using
if(isset($_GET['edit'])) {
header('Location: announcement-edit.php?AnnouncementID='.$_GET['AnnouncementID']);
}
The form later down the page to execute this is as follows
<form action="announcements.php" method="get">
<input type="hidden" name="AnnouncementID" value="<?php echo $row['AnnouncementID'];?>" />
<input name="edit" value="Modify" type="submit">
<input name="delete" value="Delete" type="submit" >
</form>
This is where it confuses me, this code worked absolutely perfectly then all of a sudden last week it stopped, 2 days ago it started working again and now broken again. When the button is clicked the URL returns as;
url/folder/announcements.php?AnnouncementID=7&edit=Modify
When its supposed to return;
url/folder/announcement-edit.php?AnnouncementID=7
If i manually type the above in the url bar it works absolutely fine and I can update the rows in the DB.
Im totally stumped as to why it is so temperamental, Have I missed something out? am I trying to do this an out dated way?
Its not like I have just followed a random person on youtube how to do this I was actually shown this way at university (only last academic year) and we was told it was "good practice". Seems very weird it works perfectly one minute then refuses to work the next.
Any thoughts or suggestions will be greatly appreciated.
You have two submit buttons in your form, which leads to triggering the submit event only once, when you press Enter key. So, when the Delete button is pressed, your GET parameters will have only delete entry and not the edit entry.
One way of tackling this is, give the same name to both and give a different value, as already there is a different value.
<form action="announcements.php" method="get">
<input type="hidden" name="AnnouncementID" value="<?php echo $row['AnnouncementID'];?>" />
<input name="action" value="Modify" type="submit" />
<input name="action" value="Delete" type="submit" />
</form>
You dont need to use form. You can do it simply using url and use tag
Try to pass your parametr via get parametr like this:
Edit
Delete
Related
Is it possible to hold the get params. in the url by switching pages?
Situation:
At the first page the user can choose between different prices.
The "submit" button is just an easy
<a href="/genrepage?price=twoDollars" value.....>
So the user does get directed from the ".../pricepage" to the ".../genrepage?price=twoDollars" url. At this point it is possible to choose between different genres. The submit button is in a ..
<form method="get" action="">
<input type="submit" name="genre" value="action">
</form>
..now the user does get redirected to the ".../genrepage?genre=action" url.
I would like to see something like ".../genrepage?price=twoDollars&genre=action.
Is it possible to realise this via WordPress (only) or would I need to code "smthg like a" plugin with php? Or is the price get param. saved in the $_Session so I could call it anyhow in the functions.php?
(Sry for this english and my bad knowledge, still learning^^)
You are obviously a web dev noob but we all have been in earlier times 😉 well in case you have a session opened (WordPress does not use sessions by default) you simply could do:
$_SESSION["price"] = $_GET["price"];
You also could start a session if none exists by adding
session_start();
in the beginning of your functions.php file.
The get variable is saved to the session then and will be available in your functions.php (and elswhere) as long as the session is alive. Save into your session whatever get/post variables you want.
If you are not using sessions you could put the price value into a hidden field at the form in the second page:
<form method="get" action="">
<!-- ... your other fields ... -->
<input type="hidden" name="price" value="<?php echo htmlentities($_GET["price"]); ?>" />
<input type="submit" name="genre" value="action">
</form>
Then on the next page both variables will available in $_GET.
Hello guys am trying to make a pagination for my website so when I get items back from the database I count the array items then I divide them on 9 cause I want always to display 9 on the page or less , to this I use the pagination links and send a get variable called "page".
now the question is how can I do the same thing when searching I mean when a user enter search keyword and then hit enter the search box will then send another get variable called "search" the problem it removes the first one "page"
I want my pagination to work for regular cases but also to work in combination with search results.
like when someone hit search the pagination changes to cycle through the search results instead of the whole web-store items .
example: examine this url :
localhost/webstore/store.php?page=1
now when user search for football for example the link would then be like this:
localhost/webstore/store.php?search=football
I want it to be like this
localhost/webstore/store.php?page=1&search=football
please help really important I should fix this today.
Thanks in advance.
Send page request in hidden format with the form, look at below code.
<form method="get" action="store.php">
<input type="text" name='search' value="" placeholder="Enter Keyword to search" />
<input type="hidden" name="page" value="1" />
<input type="submit" name="submit" value="search" />
</form>
this
<input type="hidden" name="page" value="1" /> will make your work done.
or
you can do one more way, if you are using ajax search, send query string manually by adding page=1
let's say you have query string http://localhost/webstore/store.php?search=football here add page=1 manually.
You can do that concatenate with your query string using + sign in javascript or jQuery
Hope it will serve your purpose ;)
I'm working on building a more user-friendly frontend access page in Wordpress for a content library built on ContentDM (http://www.oclc.org/support/questions/contentdm/default.htm). One of the things that was requested as part of the site was a search form that instead of searching Wordpress, goes to the ContentDM library and searches there.
It appears that the search syntax for ContentDM is as follows:
http://libraryID.contentdm.oclc.org/cdm/search/searchterm/INPUT_TERM/order/nosort
With "INPUT_TERM" being whatever the user searched for.
In other words, in order to create a search form that went directly there, I'd have to dynamically insert the contents of the input element into the middle of the "action" attribute of the form.
I'm guessing my best bet is to just send it to a PHP page that sticks $_POST['whatever'] into the URL and does a redirect. But is there in fact a way to do it dynamically from the form (ideally without Javascript) and save a step?
Thanks!
I guess something like this could work:
<form action="" method="get"
onSubmit="location.href='http://libraryID........./'+this.children[0].value+'/order/nosort; return false;">
Search: <input type="search" />
<input type="submit" value="Go" />
</form>
This will redirect the browser to the search page given in the search box, however it's not terribly reliable.
You might want to see if there's a query string "version" of the URL - maybe that search URL is affected by mod_rewrite to "look pretty", and you might be able to have http://libraryID.contentdm.oclc.org/cdm/search as the action, and have the input field named searchterm:
<form action="http://libraryID.contentdm.oclc.org/cdm/search" method="get">
Search: <input type="search" name="searchterm" />
<input type="submit" value="Go" />
</form>
I just started using twitter bootstrap, and I got stuck trying to get my form submit button to submit (PHP $_POST). Does anyone know why its not working?
No clue really..
I've been doing this previously and its been working until bootstrap:
<?php
if (isset($_POST["login"]) && $_POST["login"]=="login") {
echo "login here";
}
?>
<form action="http://mysite.com" method="post">
<input type="hidden" id="login" name="login" value="login" />
<button class="btn success" type="submit">Login</button>
</form>
The page seems to load but the PHP does not. Is the POST information being blocked?
My form input elements did not have an id or name (I didn't include them in my example).
Not an HTML expert, but I've always used <input type="submit" /> and not <button type="submit" />, not sure that button is a functional form element.
Also, your button element is closed twice - first with /> in the opening tag, and then again with a closing tag for no reason.
Maybe you are wrong with the action="http://mysite.com"? That attribute is for specifing the form data receiver, so in your case I think it's the page itself. So, if your page is named mypage.php, use action="mypage.php".
I had this same issue as well, turns out I was missing the name="submit". Gotta have that so the $_POST has a key in the assoc array!
it is adviseable that every element has a name thus (name="elementName") this makes it easy to reference them in your php scipt; also ensure that a form action and method are set.
I set a magento website with several stores, I'm making a list of all thoses stores in a page where the user can pick up the nearest one using a form like this
<form action="<?php echo ;?>" method="post">
<input type="submit" value="select store" />
</form>
<form action="<?php echo ;?>" method="post">
<input type="submit" value="select store" />
</form>
In the action attribute I would like to set the url of each store according to his Id...
Is it possible?
Is there a better way to proceed (maybe avoiding GET parameter)?
Edit:
Finally I achieve what I was looking for with this snippet
echo '<p>pick up this restaurant</p>';
It's quite close of what clockworkgeek suggest
echo '<p>pick up this restaurant</p>';
but results are differents:
my test:
http://test.mysite.com/?___store=3
clockworkgeek code:
http://test.mysite.com/___store/3/
The first link is working fine, the second lead to a 404 one...
Also I try this code which is producing nothing, Any idea why ?
Mage::app()->setCurrentStore(5);
$this->_redirect('');
The redirection is working fine, but I'm still on the same store, Is it the good way of using setCurrentStore function?
then I finally have a go with this one, but I can find suitable example on the net about it...
how can I using it, and related question how can i Hve the list of all the magento controllers ?
$this->_forward('defaultNoRoute');
thx
Perhaps you are thinking of getUrl(). For example:
echo Mage::getUrl('', array('_store'=>$storeId));
http://www.magentocommerce.com/wiki/5_-_modules_and_development/reference/geturl_function_parameters
You should bind the submit button using JQuery events and then use window.location to redirect to the selected store.
It should be quite similar to the code given in the first answer here:
Redirect automatically when selecting an item from a select drop-down list