Reputation: 1313
I have added two fields in the contact form.
Product Name:
Product Code:
I have a pre-order button on the product page so all products that is 0 quantity will have this button enabled. When the user click this button they will be redirected to the contact form.
<a href="http://localhost/store/index.php?route=information/contact"><button>Pre-Order</button></a>
Now How do i Autofill the Product Name and Product Code input in the Contact form when the user click on the Pre-Order button on the product page?
Sample Scenario:
Customer is browsing on the product Lenovo Motherboard with Product code: LV032, But he finds out that this product is out of stock and Pre-Order is only the available option. So he clicks on the Pre-Order button then customer is redirected to the contact form with the product name and product code fields already filled with the Name and Code of the Product that the customer want's to pre-order.
EDIT:
I got a working solution using sessions on the product page then using the session on the contact form. Please advise if I'm doing a right thing.
Upvotes: 1
Views: 1024
Reputation: 1313
I got it working by doing this.
I added this two lines in the product.php located in controller/product/product.php
$_SESSION['prodname'] = $product_info['name'];
$_SESSION['prodcode'] = $product_info['model'];
Now in the contact form controller contact.php located in controller/information/contact.php
I added this code.
if (isset($this->request->post['prodname'])) {
$this->data['prodname'] = $this->request->post['prodname'];
} else {
if(isset($_SESSION['prodname'])) {
$this->data['prodname'] = $_SESSION['prodname'];
} else {
$this->data['prodname'] = '';
}
}
if (isset($this->request->post['prodcode'])) {
$this->data['prodcode'] = $this->request->post['prodcode'];
} else {
if(isset($_SESSION['prodcode'])){
$this->data['prodcode'] = $_SESSION['prodcode'];
} else {
$this->data['prodcode'] = '';
}
}
Then on the success function inside controller contact.php I added this line before $this->response->setOutput($this->render());
unset($_SESSION['prodname']);
unset($_SESSION['prodcode']);
$this->response->setOutput($this->render());
Now It's working. I don't know if this is the right way to do it. If anyone has better answer please shed me some light. THanks.
Upvotes: 0
Reputation: 455
i don't exactly buy what you are trying to do, here is what i think you want to do
<a href="localhost/application/perorder.php?id=123&name=thinkpad">Pre Order</a>
now perorder.php should look like this
$id = $_GET['id']; $name = $_GET['name'];
<input type="text" value="<?php echo $name;?>" />
Upvotes: 3