PHP Codeigniter:下拉菜单中的set_value

前端之家收集整理的这篇文章主要介绍了PHP Codeigniter:下拉菜单中的set_value前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下视图,但如何将set_value应用于它而不将其默认为Please select?
<label for="add_fields_type">Type: </label>
<select name="add_fields_type" id="add_fields_type">
    <option value="">Please Select</option>
    <option value="<?PHP echo set_value('input'); ?>">Input</option>
    <option value="<?PHP echo set_value('textarea'); ?>">Text Area</option>
    <option value="<?PHP echo set_value('radiobutton'); ?>">Radio Button</option>
    <option value="<?PHP echo set_value('checkBox'); ?>">Check Box</option>
</select>

更新:

视图:

<label for="add_fields_placeholder">Placeholder: </label>
    <select name="add_fields_placeholder" id="add_fields_placeholder">
        <option value="">Please Select</option>
        <option value="<?PHP echo set_value('yes'<?PHP echo set_select('add_fields_placeholder','yes',( !empty($placeholderType) && $placeholderType == "yes" ? TRUE : FALSE ));?>">Yes</option>
        <option value="<?PHP echo set_value('no' <?PHP echo set_select('add_fields_placeholder','no',( !empty($placeholderType) && $placeholderType == "no" ? TRUE : FALSE )); ?>">No</option>
    </select>

    <label for="add_fields_placeholderValue">Placeholder Text: </label>
    <input type="text" name="add_fields_placeholderValue" id="add_fields_placeholderValue" value="<?PHP echo set_value('add_fields_placeholderValue'); ?>">

    <label for="add_fields_type">Type: </label>
<select name="add_fields_type" id="add_fields_type">
    <option value="">Please Select</option>
    <option value="input" <?PHP echo set_select('add_fields_type','input',( !empty($fieldType) && $fieldType == "input" ? TRUE : FALSE )); ?>>Input</option>
    <option value="textarea" <?PHP echo set_select('add_fields_type','textarea',( !empty($fieldType) && $fieldType == "textarea" ? TRUE : FALSE )); ?>>Text Area</option>
    <option value="radiobutton" <?PHP echo set_select('add_fields_type','radiobutton',( !empty($fieldType) && $fieldType == "radiobutton" ? TRUE : FALSE )); ?>>Radio Button</option>
    <option value="checkBox" <?PHP echo set_select('add_fields_type','checkBox',( !empty($data) && $data == "checkBox" ? TRUE : FALSE )); ?>>Check Box</option>
</select>

控制器:

$data['fieldType'] = $this->input->get('add_fields_type');
$data['placeholderType'] = $this->input->get('add_fields_placeholder');

第16行:

<option value="<?PHP echo set_value('yes'<?PHP echo set_select('add_fields_placeholder',( !empty($placeholderType) && $placeholderType == "yes" ? TRUE : FALSE ));?>">Yes</option>
这应该有所帮助:

控制器(test.PHP)

<?PHP
    class Setup extends CI_Controller {

        function index() {
            //for the set_select() function
            $this->load->library('form_validation');

            //for base_url() function
            $this->load->helper('url');

            $list['data'] = $this->input->get('add_fields_type');

            $this->load->view('test_view.PHP',$list);
        }
?>

查看(test_view.PHP)

<!DOCTYPE HTML>
<html>
<body>
<form action="<?PHP echo base_url(); ?>test">
    <label for="add_fields_type">Type: </label>
    <select name="add_fields_type" id="add_fields_type">
        <option value="">Please Select</option>
        <option value="input" <?PHP echo set_select('add_fields_type',( !empty($data) && $data == "input" ? TRUE : FALSE )); ?>>Input</option>
        <option value="textarea" <?PHP echo set_select('add_fields_type',( !empty($data) && $data == "textarea" ? TRUE : FALSE )); ?>>Text Area</option>
        <option value="radiobutton" <?PHP echo set_select('add_fields_type',( !empty($data) && $data == "radiobutton" ? TRUE : FALSE )); ?>>Radio Button</option>
        <option value="checkBox" <?PHP echo set_select('add_fields_type',( !empty($data) && $data == "checkBox" ? TRUE : FALSE )); ?>>Check Box</option>
    </select>
    <input type="submit" />
</form>
</body>
</html>

注意:set_select()的第三个参数确定是否应该选择它

原文链接:https://www.f2er.com/php/133053.html

猜你在找的PHP相关文章