Magento 1.9 – Fix Form Submission Not Loading Correct URL

actionformsfrontendmagento-1.9url

UPDATED-3

I have added a new page to front end, as you can see Adding new page to Front end, by fixing some issues, it is working now. but the issue I am facing now is in my from

    <div id="abc-category-search">
    <!--action="http://stage.oliver-marketing.com/homesearch">-->
    <!--method="post" action="<?php //echo Mage::getUrl('helloworld/index/index') ?>"--> 
    <form id="abc-category-search-form" method="post" action="<?php echo Mage::getUrl('homesearch/index/index') ?>">
        <label for="search"><?php echo $this->__('Search by product SKU/Category') ?>:</label>
        <input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('customer/session')->getFormKey(); ?>"/>
        <input id="abc-category-search-string" name="search" value="" />
        <input id="abc-category-search-cat" type="hidden" name="category" value="<?php echo $category; ?>" />
        <button id="abc-category-search-submit" type="submit" class="engine-btn" value="" >
            <?php echo $this->__('Search') ?>
        </button>
    </form>
</div>

<div id="ajax-loader" class="hide" style="">
    <p><?php echo $this->__('Searching please wait...'); ?></p>
    <img src="<?php echo $this->getSkinUrl('images/ajax_loader_green_64.gif'); ?>" />
</div>

<script type="text/javascript">
    jQuery(document).ready(function ($) {

        $("#abc-category-search-form input").keypress(function (e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $('#abc-category-search-submit').trigger('click');
                return false;
            } else {
                return true;
            }
        });
        // Attach a submit handler to the form
        $("#abc-category-search-form").submit(function (event) {
            // Stop form from submitting normally
            event.preventDefault();
            // Get some values from elements on the page:
            var $form = $(this),
                    term = $form.find("input[name='search']").val(),
                    cat = $form.find("input[name='category']").val(),
                    url = $form.attr("action");
            // Send the data using post
            var posting = $.post(url, {search: term, category: cat});
            $("#ajax-loader").show();
            // Put the results in a div
            posting.done(function (data) {
                $("#ajax-loader").hide();
                $("#abc-category-search-string").val('');
            });
        });
    });
    jQuery(document).load(function ($) {
        $("div.hero-top-content h2").html("Some Text Here")
    });
</script>

my action action="<?php echo Mage::getUrl('helloworld') gives me url to my new page, myweb.com/helloworld, but issue is that on clicking submit button on my form, it go to related controller and tried to load accurate view(my custom page),but url never changes,ideally it should be changed. if I use myweb.com/helloworld in search bar manually, it loads correct page, don't where I am doing some thing wrong
my controller is

app/code/local/Abc/Helloworld/controllers/IndexController.php

<?php

class Abc_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {
    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
    }
}

And my config.xml looks like this.

app/code/local/Abc/Helloworld/etc/config.xml

        <?xml version="1.0"?>
<config>
    <global>
        <modules>
            <Abc_Helloworld>
                <version>
                    0.1.0
                </version>
            </Abc_Helloworld>
        </modules>
        <blocks>
            <abc_helloworld>
                <class>Abc_Helloworld_Block</class>
            </abc_helloworld>
        </blocks>
    </global>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Abc_Helloworld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>
        <layout>
            <updates>
                <helloworld>
                    <file>abc_helloworld.xml</file>
                </helloworld>
            </updates>
        </layout>

    </frontend>
</config>

Best Answer

it depend on what is your <frontName>modulename</frontName>

try that with complete url

method="post" action="<?php echo Mage::getUrl('helloworld/index/index') ?>" 

you are using event.preventDefault(); that are stop form from submitting.