Welcome Guest, Not a member yet? Register   Sign In
form_dropdown() return undefined
#1

[eluser]Zied[/eluser]
Hi,
I create contact form to send message to email.
Bat i can't have the value of form_dropdown(), always I have undefined
Code:
[removed][removed]    
[removed][removed]
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/jalert.css" />
<div id="contact_form">
    &lt;?php
     echo form_open('navigation/contact_submit');
    
         $contact_comment=$this->lang->line('contact_comment');
         $contact_suggestion=$this->lang->line('contact_suggestion');
         $contact_reclamation=$this->lang->line('contact_reclamation');
         $options = array(
                      'comment'  => $contact_comment,
                      'suggestion'  => $contact_suggestion,
                      'reclamation'  => $contact_reclamation,
                    );
        
         echo form_input('name', '', 'id="name"');echo '</td></tr>';
         echo form_dropdown('subject', $options,'value="comment"');
         echo form_input('email', '', 'id="email"');echo '</td></tr>';
         $data = array('name' => 'message', 'cols' => 35, 'rows' => 12);
         echo form_textarea($data, '', 'id="message"');echo '</td></tr>';
         echo form_submit('submit', $this->lang->line('contact_submit'), 'id="submit"');
    
    echo form_close();
    ?&gt;
</div><div id="test3"></div>
[removed]
$('#submit').click(function() {
        var form_data = {
        name: $('#name').val(),
        email: $('#email').val(),
        subject: $('#subject').val(),
        message: $('#message').val(),
        ajax: '1'        
    };
    
    $.ajax({
        url: "&lt;?php echo site_url('navigation/contact_submit'); ?&gt;",
        type: 'POST',
        data: form_data,
        success: function(msg) {
            $('#test3').jAlert(msg);
        }
    });
    
    return false;
});
    
[removed]
    [removed]
        $('input').click(function(){
            $(this).select();    
        });
[removed]
#2

[eluser]Zied[/eluser]
controller:navigation
function:contact_submit
Code:
function contact_submit() {
        //load form validation
        $this->load->library('form_validation');
    
        //set form rules
        $this->form_validation->set_rules('name', 'name', 'required|max_length[50]');
        $this->form_validation->set_rules('email', 'Email', 'required|min_length[6]|valid_email');
    
        //run form validation
        $success = $this->form_validation->run();
    
        //Test ouput of form_dropdown()  
        echo $subject = $this->input->post('subject');
    
        //if the validation was a success
        if ((IS_AJAX && $success) || (!IS_AJAX && $success))
        {
            $this->load->library('email');
            
            $config['charset'] = 'utf-8';
            $config['mailtype'] = 'html';
            $this->email->initialize($config);
            
            $this->email->set_newline("\r\n");
                
            $this->email->from($this->input->post('email'), $this->input->post('name'));
            $this->email->to('[email protected]');        
            $this->email->subject($this->input->post('subject'));        
            $this->email->message(
            'Le nom de l\'exp&eacute;diteur: '.$this->input->post('name').'<br>'.
            'L\'email de l\'exp&eacute;diteur: '.$this->input->post('email').'<br>'.
            'Type de l\'email: '.$this->input->post('subject').'<br>'.
            'Le m&eacute;ssage: '.$this->input->post('message'));

            if($this->email->send())
            {
                echo 'Your email was sent, fool.';
            }
                
            else
            {
                echo 'Your email was not sent.';
            }
            
        }
    
        //if validation failed
        else { echo '<br>'.strip_tags(validation_errors()); }

    }
#3

[eluser]danmontgomery[/eluser]
You don't set the selected value of a dropdown using "value", you use "selected" on the appropriate option http://www.htmlcodetutorial.com/forms/_O...ECTED.html

Your jquery references #subject, but you never define the ID of the dropdown, so #subject doesn't exist.
#4

[eluser]Zied[/eluser]
Is the same problem, even when I used <select> with its parameters
Code:
$options = array(
                  'comment'  => $contact_comment,
                  'suggestion'  => $contact_suggestion,
                  'reclamation'  => $contact_reclamation,
                );
// all this form_dropdown is failed
echo form_dropdown('subject', $options,'id="comment"');
echo form_dropdown('subject', $options,'comment');
echo form_dropdown('subject', $options);
echo form_dropdown('id="subject"', $options,'comment');

I tested the sending of data with ajax, and I think it works
I even tried the controller and it works fine
I'm sure the problem in the <select> or also form_dropdown.
But I do not know how to fix it.
#5

[eluser]Zied[/eluser]
ok I used:
Code:
<SELECT id="subject">
     <OPTION VALUE="Commentaire" SELECTED >&lt;?php echo $contact_comment ?&gt;
     <OPTION VALUE="Suggestion" >&lt;?php echo $contact_suggestion ?&gt;
     <OPTION VALUE="R&eacute;clamation" >&lt;?php echo $contact_reclamation ?&gt;
</SELECT>




Theme © iAndrew 2016 - Forum software by © MyBB