开发者

How to call a controller withour going to the url in magento

开发者 https://www.devze.com 2023-03-23 00:06 出处:网络
I am new to magento. I needed to know if its possible to call a controller without going to url. What i want to do is to call the controller but staying on the same page. I have a form on the front en

I am new to magento. I needed to know if its possible to call a controller without going to url. What i want to do is to call the controller but staying on the same page. I have a form on the front end which accepts user input and than call a controller to save the data in the database by using models. Eveything works ok but my problem is that when user click on submit button the user goes to the controller url but i want to stay on the same page but call the controller. here is my code

<?php $_product = $this->getProduct(); ?>


<form id="test" action="<?php echo Mage::getUrl('pricenotify/pricenotify/db') ?>" method="post">

            <label for="price">Price *</label>
            <input type="text" id="price" name="price" value="" class="required-entry validate-number"/><br />
            <label for="email">Email Address *</label>
            <input type="text" id="email" name="email" value="" class="required-entry validate-email"/>
            <input type="hidden" id="id" name="id" value="<?php echo $_product->getId() ?>" />
            <input type="hidden" id="propri" name="propri" value="<?php e开发者_如何学编程cho $_product->getPrice() ?>" />

            <input type="submit" name="submit" value="<?php echo $this->__('Submit') ?>" />


</form>

<script type="text/javascript">
//< ![CDATA[
var customForm = new VarienForm('test',true);
//]]>
</script>


The simplest way to convert to AJAX is to modify the button like this:

<input type="submit" name="submit" value="<?php echo $this->__('Submit') ?>"
    onclick="if(customForm.validator && customForm.validator.validate()) this.form.request(); return false;" />

It doesn't do anything with the results, just calls the relevant controller/action.

0

精彩评论

暂无评论...
验证码 换一张
取 消