Prestashop smarty make a form for user and save the input fields to the database? - module

In Prestashop I am doing a module. In that module I have view file(smarty template). In smarty I am doing form so that user can submit the form from frontend. Now when user makes fill the form and clicks on submit then the form should save all the vales to thae database. So for that in smarty I made a form like this
<div id="content" class="form-wrapper" >
<div class="form-content">
<input type="text" id="name" name="name" placeholder="Name" /> <br />
<input type="text" id="email" name="email" placeholder="email"/> <br />
<input type="text" id="phone" name="phone" placeholder="Phone Number"/> <br />
<input type="submit" name="submit-query" id="submit-enquiry" value="submit" />
</div>
</div>
and in the file where the values will be submitted I have made my code like this
<?php
include '../../../config/settings.inc.php';
include '../../../config/defines.inc.php';
include '../../../config/config.inc.php';
include(dirname(__FILE__).'/../../../../init.php');
if(Tools::getValue('submit-query')) {
$this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
}
else {
$this->_html .= $this->displayError($this->l('You Have Some Errors'));
}
?>
Now when doing click on my submit button It is showing error like this
Fatal error: Using $this when not in object context in file.php on line 11
Now can someone kindly tell me what is the issue here and how can I make a form in smarty for frontend users so that they can submit the form and the value will be stored to the database. Any help and suggestions will be really appreciable. Thanks

First I would recommend to do the processing inside of your module, e.g. in init() function, you can get your module link using $this->context->link->getModuleLink('myModuleName'); and add it to the form action attribute, all variables can be assigned using $this->context->smarty->assign().
Storing values in database is quite a wide question. You have to provide some more details about it.
Check some tutorials from Prestashop e.g. Creating a Prestashop Module. You will find most of your answers there.

Related

How to stay on the same page after a form submission integrated to a Google form

In my website i have a contact form, and i've integrated it with a Google form. I've added the google form's execute URL as the action URL so once its submitted the form is being populated with the form data. the way i have done it
But when its being submitted, its redirecting to a google form's response page. What i need is once its submitted, to stay on the same page and give an alert. Im not sure how to do this in vue js. Any suggestion will be appreciated.
the content on the redirected page
{"result":"success","data":"{\"name\":[\"sdvsdv\"],\"company\":[\"dsvdv\"]}"}
Form in vue js view
<form method="POST" id="appointment-form" action="https://script.google.com/macros/s/AKfycbzRHvjfmIZdwKnOm26PeFv64OyyyGAfcr68MxvYw/exec">
<div class="form-group">
<input type="text" placeholder="Your name" name="name" class="form-control" id="name" required>
</div>
<div class="form-group">
<input type="text" placeholder="Company name" name="company" class="form-control" id="company" required>
</div>
<buttontype="submit" class="btn btn-default btn-block form-submit-btn">Submit</button>
</form>
After read your code properly, i found many errors.
How are you saving input values?
To save, you have to use ```v-model directive````
I guess you save the input values in somewhere. To avoid your problem, you can add a method and call it on submit, and inside the method save your input values.

Validations not working in ODOO website

I have created a template and a controller for it in ODOO v8. Following is the template:
<template id="myTemplate">
<t t-call="myTemplateHeader"/>
<div class="myClass">
<form action="/myControllerAction" name="myTemplateForm">
<input type="text" id="name" name="name"/>
<input type="text" id="lname" name="lname"/>
<input type="text" id="email" name="email"/>
<input type="submit" value="Submit"/>
</form>
</div>
</template>
And I have written a controller for the action /myControllerAction.
#http.route(['/myControllerAction'], type='http', auth="public", website=True)
def index(self, **post):
data = {}
# some action here
# to submit and fetch values
request.website.render("my_module.mySecondTemplate", data)
I have added validations on the fields in the form so that one cannot submit the form without entering the values in all the text fields given. The validations in JS works, it shows an alert message when the text fields are blank(one alert for each text field). But, after clicking the OK for the alert message of email field, it submits the form even when the field is empty. I have checked the issue and found that the problem exists only if I provide
<input type="submit" value="Submit"/>
and it will be solved if I am using
<input type="button" value="Submit"/>
But I have to make some calculations in the controller and need to retrieve some data from the database to show on the next page. For this, type="button" cannot be used as it just submit the form and redirect to next page without making a call to the controller function. type="submit" will make the call to the controller, but validations are not working as described earlier. Also submitting the form using onclick event of the button in javascript won't call the controller. I want validations on the form and then call the controller(on submit). Is there any way I could implement this in ODOO v8?
For making fields mandatory in ODOO templates, the attribute required="required" can be used on input fields.
<input type="text" id="name" name="name" required="required"/>

Am trying to create an item in the cart for a Big Commerce store and it keeps redirecting to the item page I just left

We are working on behalf of a Big Commerce store owner and are trying to add items to the shopping cart by posting the same data that the regular item page posts, except it is done by an external program on another server. This is because we intercept the post (which is done via a postbackurl on an iframe included in the item page that allows the customer to customize the item)... and then repost the same data to the cart.
This was working in our test store but not in the client store. I'm wondering if the difference is that when the item page posts, the Origin header is of course from that store. WHen I post it from my program, the origin header is different. How can I tell what the real issue is?
Is there a setting in Big Commerce that allows posts from another origin?
Or, how do I add a store product from an external program into the Big Commerce cart?
Thanks,
Cindy
Yes, the product has options... I am not posting them in the form below but it makes sense that I should.
Here is a sample of my code:
<script type="text/javascript">
function submitform() {
document.forms["redirectpost"].submit();
}
</script>
</head>
<body onLoad="submitform();">
<form name="redirectpost" method="post" action="http://eystudios8.mybigcommerce.com/cart.php" enctype="multipart/form-data">
<input type="hidden" name="action" value="add">
<input type="hidden" name="product_id" value="211">
<input type="hidden" name="variation_id" vale="">
<input type="hidden" name="currency_id" value="">
<input type="hidden" name="qty[]" value="1">
<input type="hidden" name="ProductFields[1]" value="<?php echo $docsession; ?>">
<input type="submit" value="" style="display:none;">
</form>
I also have a configurable field I am attempting to post the docsession to.
Cindy
Adding this question:
I see that I need to post the options in my form - how do I know what field name to call each option? There are about 15 options I need to forward to the cart page. Cindy

Products default sort not working on search.tpl - Prestashop 1.6.0.6

I set up in backoffice the default sort type to : in stock. this works for all pages except SearchController template file : search.tpl.
What can be the causes behind such dysfunctionning? I really don't know what part of code to deal with. Thanks everyone who already met such issue for advices.
Edit:
I discovered that the link in the adress bar after click on search button is:
website/index.phpcontroller=search&orderby=position&orderway=desc&search_query=design+40&submit_search=Rechercher
When I remove orderby=position&orderway=desc, the default behaviour works. I just need to remove this action from controller but still don't know how.
In template file, I found:
<form method="get" action="{$link->getPageLink('search')|escape:'html'}" id="searchbox">
<p>
<label for="search_query_top"><!-- image on background --></label>
<input type="hidden" name="controller" value="search" />
<input type="hidden" name="orderby" value="quantity" />
<input type="hidden" name="orderway" value="desc" />
<input class="search_query" type="text" id="search_query_top" name="search_query" value="{$search_query|escape:'html':'UTF-8'|stripslashes}" />
<input type="submit" name="submit_search" value="{l s='Search' mod='blocksearch'}" class="button" />
</p>
</form>
As you see, I have already changed the value of the hidden input to quantity. Hope it helps.

Google Custom Search with SEO URL

Well i have this search engine into my site
<form action="/apps/search/" name="g_search" id="cse-search-box" method="post">
<input type="hidden" name="cof" value="FORID:11;NB:1" />
<input type="hidden" name="ie" value="utf-8" />
<input type="text" autocomplete="off" name="google_seach" class="search-text" onfocus="searchtext('focus')" onblur="searchtext('blur')" />
<label style="color:#796b6b;float:left;padding:0;">|</label>
<input type="submit" style="float:right;margin-top:3px;cursor:pointer;width:16px;height:16px;background:url(/template/img/main/search-icon.jpg);border:none;" value="" alt="Αναζήτηση" title="Αναζήτηση" />
</form>
Now i want some code to results page.Somehow the post request readed from a file called search.php
This file have access to $_POST[] array..
The file initializes $selector variable (for template use).
What we want to echo into contentarea div must put into $body variable..
Any help?
<?php
$selector="search";
$body="<div id=\"cse-search-form\" style=\"width: 100%;\">Loading</div>";
?>
I have a similar issue, just use GCS code provide by Google as it easy, make sure in the option in GSE you select to visualize the search result on your page and not an Iframe