ovy79ro Posted June 14, 2016 Share Posted June 14, 2016 Hello, I want to know how to keep selected option after submit. For example, I have the following select input: ................................................ <select name="id_supplier"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> .................................................. If i select option 2, for example, after submit, selected value is not kept and returns to the first option, o. I try the following code but it is not working. ................................................ <select name="id_supplier"> <option value="0" {if isset(($id_supplier) && $id_supplier==0) selected="selected"}{/if}>0</option> <option value="1" {if isset(($id_supplier) && $id_supplier==1) selected="selected"}{/if}>1</option> <option value="2" {if isset(($id_supplier) && $id_supplier==2) selected="selected"}{/if}>2</option> <option value="3" {if isset(($id_supplier) && $id_supplier==3) selected="selected"}{/if}>3</option> </select> .................................................. Can someone help me? Thank you! Link to comment Share on other sites More sharing options...
ovy79ro Posted June 14, 2016 Author Share Posted June 14, 2016 Anyone? Link to comment Share on other sites More sharing options...
rocky Posted June 15, 2016 Share Posted June 15, 2016 How is $id_supplier being set? Are you using Tools::getValue('id_supplier')? That's what PrestaShop usually uses to make the values persist even if there's an error message. Link to comment Share on other sites More sharing options...
ovy79ro Posted June 15, 2016 Author Share Posted June 15, 2016 $id_supplier get value with $_POST. I dont use Tools. Link to comment Share on other sites More sharing options...
rocky Posted June 15, 2016 Share Posted June 15, 2016 You can try setting the value on the <select> like this: <select name="id_supplier"{if isset($id_supplier)} value="{$id_supplier|intval}"{/if}> Link to comment Share on other sites More sharing options...
ovy79ro Posted June 15, 2016 Author Share Posted June 15, 2016 Thank you but don't working. Link to comment Share on other sites More sharing options...
ovy79ro Posted June 15, 2016 Author Share Posted June 15, 2016 Solved! Work with this: <option value="1" '.(Tools::getValue('id_supplier') == 1 ? 'selected="selected"' : '').'>1</option> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now