Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter form_open() action not working correctly
    primarykey
    data
    text
    <p>I have have a view in which there's a form that manages products (either add new product or -if an id passed- editing an existing one). If an id is passed then the form action should be eg 'admin/product/manage/5', if no id passed then it should be like this 'admin/product/manage'. </p> <pre><code>&lt;?php echo form_open('admin/product/manage/{optional product id}', array('class' =&gt; 'ajax-form')); ?&gt; </code></pre> <p>I have also created and this route:</p> <pre><code>$route['admin/product/manage'] = "admin/product/manage"; $route['admin/product/manage/(:num)'] = "admin/product/manage/$1"; </code></pre> <p>How can I make my form action work correctly? is it possible to put inside the action the route somehow??</p> <p>This is my Controller:</p> <pre><code>public function manage($id = NULL){ //fetch a single product to edit or create a new one if (isset($id) === true) { $data['prod'] = $this-&gt;product_model-&gt;get($id); $data['vers'] = $this-&gt;product_version_model-&gt;get_by('product_id',$id); } else { $data['prod'] = $this-&gt;product_model-&gt;make_new();// this returns $product-&gt;product_name = ''; in order to be empty the input field and not throughing errors } $this-&gt;product_model-&gt;save_product(); $this-&gt;product_version_model-&gt;save_version(); // load the view $this-&gt;layout-&gt;view('admin/products/manage', $data); } </code></pre> <p>This is my view:</p> <pre><code>&lt;?php echo form_open('admin/product/manage', array('class' =&gt; 'ajax-form')); ?&gt; &lt;p&gt; &lt;label for="product_name"&gt;Product *&lt;/label&gt; &lt;input type="text" name="product_name" value="&lt;?php echo set_value('product_name', $prod-&gt;product_name); ?&gt;" /&gt; &lt;?php echo form_error('product_name'); ?&gt; &lt;/p&gt; &lt;?php echo form_close() . PHP_EOL; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload