2

I don't know what i'm doing wrong and im stuck in this part of my project so any help would be appreciated

here is my html:

<form id="form_search" method="post" action="/controler/something">
<select id="tip_fam" maxlength="100" >
<option value="1">something 001</option>
<option value="2">something 002</option>
<option value="3">something 003</option>
<ul id="print" class="bot"><li>Print</li></ul>
</form>

JS:

$("#print").click(function(){
        url = base_url+"index.php/almacen/product/create_pdf/"+$("#tip_fam").val();
        window.open(url,'',"width=800,height=600,menubars=no,resizable=no;")
    });

Php (codeigniter) :

public function create_pdf(){       

    $tip_fam = $this->input->post('tip_fam');

i thought i could get the value of the select this way but when i print it in a var_dump(), it shows me "boolean false".

8
  • 1
    can't make a post with window.open ... need to submit form to _blank target, or use a get Commented Oct 15, 2015 at 3:13
  • Like what @charlietfl said, to access the post data you have to submit the form. What you're doing is just opening a new window. Commented Oct 15, 2015 at 3:14
  • thanks for answering, i'm going to try as @charlietfl says but i'm wondering if there is a way to send parameters to that php function Commented Oct 15, 2015 at 3:27
  • sure, as query string get params or codeigniter url segments Commented Oct 15, 2015 at 3:28
  • i think i didn't explain it properly. i have more than one button and i did a submit already so i thought opening a new window with js would submit the form but i was clearly wrong, do you have an example how i can do that please? Commented Oct 15, 2015 at 3:42

2 Answers 2

2

to send value in url and to use in controller, you should capture that vales in parameter of the function. Change your code like this, it will work.

public function create_pdf($tip_fam){       

     echo $tip_fam;// will echo the value which you passed from view.
Sign up to request clarification or add additional context in comments.

Comments

1

You don't actually have to use javascript. I would do it this way.

EDIT: You can have more than one submit button. Just check it in your function.

View:

<form id="form_search" method="post" action="/controller/something">

    <select id="tip_fam" maxlength="100">
        <option value="1">something 001</option>
        <option value="2">something 002</option>
        <option value="3">something 003</option>
    </select>

    <input type="submit" name="print" id="print" value="Print">
    <input type="submit" name="print" id="print" value="PrintAndSave">

</form>

Controller:

public function something()
{
    // Check which button was clicked
    $submit_button = $this->input->post('print');

    if( $submit_button == 'print' )
    {
        // Do print
    }
    elseif( $submit_button == 'printAndSave' )
    {
        // Do print and save
    }
}

4 Comments

i was trying to do it that way because i have more than one bottom and one of them is already using that action
What do you mean by more than one bottom? You meant more than one button? Like you already have a submit button so this is another button?
yes, that's exactly what i meant i'm sorry my mistake
thank you, i didnt know this could be done i'm going to try it now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.