1

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>
  • you can use action="<?php echo Mage::getUrl('myweb/helloworld') – Rakesh Jesadiya Jun 27 '16 at 5:43
  • @Rakesh please see my updated post, – Abdul Ghaffar Jun 27 '16 at 5:49
  • in which Action of Controller are you want to submit form? – Amit Bera Jun 27 '16 at 5:51
  • @AmitBera please have look on update – Abdul Ghaffar Jun 27 '16 at 5:54
  • I have just one Action in my Controller – Abdul Ghaffar Jun 27 '16 at 5:54
2

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.

  • this is not working – Abdul Ghaffar Jun 27 '16 at 6:13
  • which url it is taking too? – Qaisar Satti Jun 27 '16 at 6:14
  • I have update my post – Abdul Ghaffar Jun 27 '16 at 6:17
  • As you asked, currently it is on Home page myweb.com, after action it it should be changed to myweb.com/helloworld – Abdul Ghaffar Jun 27 '16 at 6:18
  • 1
    I am using event.preventDefault();, add some other data before submission, if I remove event.preventDefault() it work, now have to figure an other way to pass data....thanks – Abdul Ghaffar Jun 27 '16 at 6:28
2

Your module url work like

routename/controllername/actionname

In your case route is helloworld

Controllername is IndexController so name is index

Action name of IndexController.php file where you need to send your form data we considering indexAction name is index

As per url

routename/controllername/actionname

In your case url will be

helloworld/index/index

  • this is not working – Abdul Ghaffar Jun 27 '16 at 6:13
  • 1
    Your url is <?php echo Mage::getUrl('helloworld/index/index') ?> – Prashant Valanda Jun 27 '16 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.