I have a <?php print $search_box; ?> in my page.tpl.php page. On pages that exist, the search works, but on 404 pages, it does not.
I saw some bugs/patches threads over at drupal.org for D6.15, but none of them seem to work according to the thread and they weren't really relevant to D5.x
I have a theory that the because the <?php print $search_box; ?> creates a form with an action to itself(a non-existant page), it'll get the 404.
Has anyone run up against this? If so, how did you fix it?
One theory I has was to somehow tap into the form and always make the action="/" (front page) which would always exist.
If this is a good idea, how does one go about tapping into the FormAPI and overwriting the action? Is it a preprocess function?
In a form alter you can use drupal_get_headers() to check if the page being displayed is a 404.
If it is a 404, you can in your form alter set the $form['#action'] attribute in your search form to fx the front page or any other page that you would like to redirect the user to.
I haven't tested this, but it should work.
Related
I'm trying to learn PHP, and to do so im trying to create a code to register new products, i've made an loggin access where the person to do so needs to be connected, so inside of the cpanel I did differents sections, like add client, add product...
So i did an index in the _cpanel folde where i have my main html and to not repeat the same html i put an include inside this index so i can call others php files inside.
I dont know if its correctly to do like this BUT, as i said Im new at programming..
But everything works pretty good, until i need to call my post in my url..
like.. to add a new product i need to go to :
localhost -> connect... to go to localhost/_cpanel
if i click in add a new produt, i go to localhost/_cpanel/?page=folder/addnewproduct.php
and inside this php file i put a form with an action="?go=addnewproduct"
so, i did everything to put all the info in my db, but when i submit it goes to
localhost/_cpanel/?go=addnewproduct and nothing happens..
i tried to change the action like action="folder/?page=addnewproduct.php&?go=addnewproduct" but it doesnt work either.
BUT i made it works changing to action"folder/addnewproduct.php?go=newproduct
but to do so i need to go to "addnewproduct.php", and this page only is an included page inside my index..
i could call back to the index page after adding a new product, so that it doesnt show this page only, but when posting it loads fast to the page and after than it go back to my _cpanel.
i tried to find solutions but, didnt find... i think its just a problem with the way i put it in my action, maybe theres a way to do it and i dont know it yet.
I don't think I get what you're wanting exactly, but here you go:
If you're trying to redirect the request, you may just use the header function as follows:
header('Location: target/url.php');
If you want to make a external post request with php, you may use curl, as suggested here:
PHP + curl, HTTP POST sample code?
I have created a page template in WordPress to display a form with action="". Very simply, it will not post any of the form data upon submission. I have tried var_dump($_POST) but it just gives me array(0) {} every single time. I've tried examples provided by some websites for creating a form, but I can't reproduce the same results.
I have thoroughly search for answers to this problem but nothing seems to work. It must be something internal or very advanced. I just want to know why my form data won't post and where it might be going.
Check your data using a non-WP page, meaning put a php file in web-root, and have the form action point to it, such as ...action="/formtest.php", and on that page:
<?php
var_dump($_POST);
?>
This will test if you really aren't getting the POST vars. Then, since you'll 99% likely find they ARE being posted, the likely trouble is that your page IS being redirected somewhere by the theme as mentioned elsewhere (e.g. my theme includes a hook on 'template_redirect'...).
If you are theme savvy and just looking for a quick fix- at the expense of losing it on theme upgrade- you can create an exception just for your temp.php page, but the way that many developers handle it is via Plugins, or handle your form via Ajax. Many others have encountered this same issue, and so, either tacking on code to a Plugin, or performing in-page Ajax (since you are submitting to SELF anyway...).
This page will give you a leg-up on WP Ajax, it's a reputable and well written doc.
I'm fairly new to cakephp, so I may just be setting things up wrong here.
I have created a simple blog with comments and posts (among other things).
I can add Comments while viewing a Post which submits back to the Comments controller (/controllers/comments/add).
The problem that I am running into is that when there are validation errors, it displays them in the /views/comments/add view, rather than the view where I was adding the comment /views/posts/view.
This has to be a pretty common thing to do I'd think, where am I going wrong?
You can ask the add method of the comments controller to render a different view:
$this->render('/Posts/view');
But then of course you'll need to make sure all the data that the 'Posts/view/' file needs is collected and set by the add method of the Comments controller.
Instead, what I would do is just make the comment form submit via AJAX (you know about AJAX?). That way, you can render the Comments/add view (or the appropriate part of it) without refreshing the rest of the page.
Of course, users with Javascript disabled will still have to go to a different page to correct their errors. But that shouldn't happen often, and you can always just redirect them back to the Posts page once they successfully submit their comment.
If you're new to CakePHP, and you're going to use AJAX, you'll probably want to use something like this somewhere:
if ($this->request->is('ajax')) {
$this->render('/Elements/ajax_comment_form');
}
// If it's not AJAX it'll fall through and show the regular comment add.ctp view
I've a drupal site with some plugins, everything is running fine, but i don't know why, in my frontpage this code isn't working:
if($is_front){
if ($messages):
print $messages;
endif;
}
If i try to do a var_dump of messages, it results in empty string.
The same code, on other pages (not front) is working.
This variable is used when showing sys/drupal messages (ex: after user registration), if i set the user registration to show a page different than the frontpage, the message is showed, otherwise it's not.
Thanks
You obviously know that $messages is only populated when you submit a form and validation fails or something similar. I wonder if perhaps, that variable is being cleared upon redirection to the homepage and thus not showing up???
I assume you have a form or something on the homepage which you are submitting?
Cheers,
Alex
I have a post html form, and the action is index.php, which is the websites main page. I never actually have index.php in the address bar, since links to "/" go to it, and even if I did, it would be website.com/home(/), since I use rewrite rules. So basically, the user should never see index.php. However, the form submit doesn't work if the action isn't spefically index.php, "/" doesn't work, even though that resolves to index.php. Any ideas on how to get around this?
Don't specify the action. If the post is to the page they're on, the default action of the form is to post to that.