insert form_dropdown data into mysql database in codeigniter - mysql

I am new in codeigniter and trying to insert form_dropdown data into database, But i am unabl to insert selected option into database.
This is my model:
public function insertUser()
{
$data1 = array(
'id'=>$this->input->post('id'),
'full_name'=>$this->input->post('full_name'),
'email'=>$this->input->post('email'),
'contact_no'=>$this->input->post('contact_no'),
'role'=>$this->roles[0],
'status'=>$this->status[0]
);
$this->db->insert('users',$data1);
$data2['user_id']=$this->db->insert_id();
$data2 = array(
'type_of_paper'=>$this->input->post('type_of_paper'),
'deadline'=>$this->input->post('deadline'),
'acadmic_level'=>$this->input->post('acadmic_level'),
'quality'=>$this->input->post('quality'),
'noofpage'=>$this->input->post('noofpage'),
'subject_area'=>$this->input->post('subject_area')
);
$this->db->insert('orders',$data2);
return $this->db->insert_id();
}
This is my controller:
public function order()
{
$data['title']='Order';
$data['page']='order';
$data['type_of_paper'] = $this->writer_model->getTypeOfPaper();
$data['deadline'] = $this->writer_model->getDeadline();
$data['prices'] = $this->writer_model->getPrice();
$data['acadmic_level']=$this->writer_model->getAcadmicLevel();
$data['quality']=$this->writer_model->getQuality();
$data['subject_area']=$this->writer_model->getSubjectArea();
$data['currencies']=$this->writer_model->getCurrency();
$this->form_validation->set_rules('full_name', 'Full Name', 'trim|required|min_length[5]|max_length[50]|is_unique[users.full_name]',
array(
'required' => 'You have not provided %s.',
'is_unique' => 'This %s already exists.'
));
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]',
array(
'required' => 'You have not provided correct %s.',
'is_unique' => 'This %s already exists.'
));
$this->form_validation->set_rules('contact_no', 'Contact No', 'trim|required');
$this->form_validation->set_rules('type_of_paper', 'Type Of Paper', 'trim|required');
$this->form_validation->set_rules('deadline', 'Deadline', 'trim|required');
$this->form_validation->set_rules('acadmic_level', 'Acadmic Level', 'trim|required');
$this->form_validation->set_rules('quality', 'Quality', 'trim|required');
$this->form_validation->set_rules('noofpage', 'No Of Pages', 'trim|required');
$this->form_validation->set_rules('subject_area', 'Subject Area', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header', $data);
$this->load->view('navbar', $data);
$this->load->view('order', $data);
$this->load->view('footer', $data);
}else
{
if($this->user_model->isDuplicate($this->input->post('email')))
{
$this->session->set_flashdata('flash_message', 'User email already exists');
redirect(site_url().'/home/login');
}else
{
$config=array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '',
'smtp_pass' => '',
'mailtype' => 'html'
);
$clean = $this->security->xss_clean($this->input->post(NULL, TRUE));
$id = $this->user_model->insertUser($clean);
$token = $this->user_model->insertToken($id);
$qstring = $this->base64url_encode($token);
$url = site_url() . '/home/complete/token/' . $qstring;
$link = $url;
$message = '';
$message .= 'You have signed up with our website.
Please click here to verify your email address:'. $link;
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('','Gourav shukla');
$this->email->to($this->input->post('email'));
$this->email->subject('This is an email Test');
$this->email->message($message);
$this->email->send();
/*if($this->email->send();)
{
echo 'Your email was sent, fool.';
}else
{
show_error($this->email->print_debugger());
}
echo $message; send this in email
exit;*/
};
}
}
This is my view code:
<?php // Change the css classes to suit your needs
$attributes = array('class' => 'form-horizontal', 'id' => 'order_form', 'name' => 'order_form');
echo form_open('/home/order', $attributes); ?>
<h3>Customer Information :</h3>
<?php echo form_input(array('name'=>'full_name', 'id'=> 'full_name', 'placeholder'=>'Full Name', 'class'=>'full_name', 'value' => set_value('full_name'))); ?>
<?php echo form_error('full_name');?>
<?php echo form_input(array('name'=>'email', 'id'=> 'email', 'placeholder'=>'Email', 'class'=>'email', 'value'=> set_value('email'))); ?>
<?php echo form_error('email');?>
<?php echo form_input(array('name'=>'contact_no', 'id'=> 'contact_no', 'placeholder'=>'Contact No', 'class'=>'contact_no', 'value'=> set_value('contact_no'))); ?>
<?php echo form_error('contact_no');?>
<hr />
<h3>Order Pricing :</h3>
<?php $attributes = 'id="type_of_paper" class="form-control"';
echo form_dropdown('type_of_paper', $type_of_paper, set_value('type_of_paper'), $attributes);?>
<?php echo form_error('type_of_paper'); ?>
<?php $attributes = 'id="deadline" class="form-control"';
echo form_dropdown('deadline', $deadline, set_value('deadline'), $attributes); ?>
<?php echo form_error('deadline'); ?>
<select class="form-control" id="acadmic_level" name="acadmic_level" onchange="calculateTotal()">
<option value=""> - Acadmic Level - </option>
<?php foreach($acadmic_level as $row)
{
echo '<option value="'.$row->value.'" id="'.$row->level_name.'">'.$row->level_name.'</option>';
}
?>
</select>
<?php echo form_error('acadmic_level'); ?>
<select class="form-control" name="quality" id="quality" onchange="calculateTotal()">
<option value=""> - Quality - </option>
<?php foreach($quality as $row)
{
echo '<option value="'.$row->q_value.'" id="'.$row->q_type.'">'.$row->q_type.'</option>';
}
?>
</select>
<?php echo form_error('quality'); ?>
<br />
<input type="text" maxlength="150" name="noofpage" id="noofpage" placeholder="No Of Pages" onkeyup="calculateTotal()"/>
<?php $attributes = 'id="price" class="form-control"';
echo form_dropdown('prices', $prices, set_value('prices'), $attributes); ?>
<input id="amount" name="amount" placeholder="Amount in British Pound(£)" type="text" />
<?php echo form_error('noofpage'); ?>
<select class="form-control" name="currency" id="currency" onchange="getCurrency()">
<?php foreach($currencies as $row)
{
echo '<option value="'.$row->rate.'">'.$row->name.'</option>';
}
?>
</select>
<?php echo form_error('currency'); ?><br />
<div id="finalPrice"></div><br />
<div id="totalPrice" name="totalPrice"></div>
<hr />
<h3>Order Information :</h3>
<select class="form-control" id="subject_area" name="subject_area">
<option value=""> - Subject Area - </option>
<?php foreach($subject_area as $row)
{
echo '<option value="'.$row->subject_area.'">'.$row->subject_area.'</option>';
}
?>
</select>
<?php echo form_error('subject_area'); ?>
<?php echo form_input(array('name'=>'required_topic', 'id'=> 'required_topic', 'placeholder'=>'Required Topic', 'class'=>'required_topic', 'value' => set_value('required_topic'))); ?>
<?php echo form_error('required_topic');?><br />
<?php echo "<input type='file' name='userfile' size='20' />"; ?><br />
<?php $data = array('name'=> 'vc_desc','id'=> 'vc_desc','value'=> set_value('vc_desc'),'rows'=> '6','cols'=> '10','placeholder'=>'Detailed Instructions','style'=> 'width:50%; margin-left:100px','class'=> 'form-control');
echo form_textarea($data); ?><br />
<hr />
<h3>Select Payment Method :</h3>
<?php echo form_radio("gender", "Female", NULL, set_radio('gender', 'Female')); ?>Female
<?php echo form_radio("gender", "Male", NULL, set_radio('gender', 'Male')); ?>Male<br />
<input type="checkbox" name="accept_terms_checkbox" value="Accept TOS" /> Accept Terms of Services<br>
<?php echo form_error('accept_terms_checkbox') ?>
<?php echo form_submit(array('value'=>'Place Order', 'class'=>'btn btn-md btn-primary btn-block')); ?>
<?php echo form_close(); ?>
When i am running this code then i am getting this output:
output image
but i want to store option name into database not value from option.
Please fix this problem.
thanks in advance.

what i got from your last two lines and image that is data is inserting into database but values are inserting and you wants to insert names,
if i correct then,
you have to use your names in options value like
<option value="name">name or anything you want</option>
in form_dropdown
$style=array("id"=>"any_id","class"=>"any_class");
$dd_data=array();
$dd_data['']="-select-";
foreach($data as $row) // $data coming from server
{
$dd_data[$row['name']]=$row['name or anything'] // $row['name'] names that you wants to add into database
}
echo form_dropdown('field_name',$dd_data,'',$style);
this code is just an example it is not tested.

Related

I would like to put search bar beside a page selector

I'm newbie and I would like to know the way to put search bar beside page selector.
Here's a screenshot now :
https://imgur.com/a/S9X3sIc
My desire layout :
https://imgur.com/a/0zx3rfl
How can I make it? I need your help. Thanks in advance. I love you guys. :D
<div class="wpf-navi <?php echo esc_attr($class) ?>">
<div class="wpf-navi-wrap">
<div id="wpf-widget-search" class="wpforo-widget-wrap"><form action="<?php echo wpforo_home_url() ?>" method="get">
<?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
<input type="text" placeholder="<?php wpforo_phrase('Search...') ?>" name="wpfs" class="wpfw-70" value="<?php echo isset($_GET['wpfs']) ? esc_attr(sanitize_text_field($_GET['wpfs'])) : '' ?>" ><input type="submit" class="wpfw-20" value="»">
</form></div>
<span class="wpf-page-info">
<?php wpforo_phrase('Page') ?> <?php echo intval($paged) ?> / <?php echo intval($pages_count) ?>
</span>
<?php if( $paged - 1 > 0 ): $prev_url = ( ($paged - 1) == 1 ? $sanitized_current_url : sprintf($url, $paged - 1) ); ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit($prev_url) ) ?>" class="wpf-prev-button" rel="prev">
<i class="fas fa-chevron-left fa-sx"></i> <?php wpforo_phrase('prev') ?>
</a>
<?php endif ?>
<select class="wpf-navi-dropdown" onchange="if (this.value) window.location.assign(this.value)" title="<?php esc_attr( wpforo_phrase('Select Page') ) ?>">
<option value="<?php echo esc_url( WPF()->user_trailingslashit($sanitized_current_url) ) ?>" <?php wpfo_check($paged, 1, 'selected') ?>>1</option>
<?php for($i = 2; $i <= $pages_count; $i++) : ?>
<option value="<?php echo esc_url( WPF()->user_trailingslashit( sprintf($url, $i) ) ) ?>" <?php wpfo_check($paged, $i, 'selected') ?>>
<?php echo $i ?>
</option>
<?php endfor; ?>
</select>
<?php if( $paged + 1 <= $pages_count ): ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit(sprintf($url, $paged + 1) ) ) ?>" class="wpf-next-button" rel="next">
<?php wpforo_phrase('next') ?> <i class="fas fa-chevron-right fa-sx"></i>
</a>
<?php endif ?>
</div>
</div>

WooCommerce - Add Country/State Select Fields to Registration Form?

I've read through, and followed the following tutorial How to add custom fields in user registration on the "My Account" page and successfully added several custom fields to the registration form on the My Account page (seen when users are logged out).
I'd like to add billing country/state as select fields if the shop owner has defined them. (i.e. If the shop only services Canada, load only Provinces).
Unfortunately the tutorial doesn't cover select fields, just basic text fields. I did find another thread that lists how to add countries but it's all countries, not the ones specified by the shop owner.
Anyone have any further insight in loading Countries/Provinces/States that are set by the shop owner? So far I've got the following:
/**
* Add new register fields for WooCommerce registration.
*
* #return string Register fields HTML.
*/
function wooc_extra_register_fields() {
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');
?>
<fieldset>
<legend><h3>Address</h3></legend>
<p>Please provide the main contact address for this account.</p>
<p class="form-row form-row-wide">
<label for="reg_billing_address_1"><?php _e( 'Address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" placeholder="Street/P.O Box address" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_address_2"><?php _e( 'Address Line 2', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_address_2" id="reg_billing_address_2" placeholder="Apartment, suite, unit etc. (optional)" value="<?php if ( ! empty( $_POST['billing_address_2'] ) ) esc_attr_e( $_POST['billing_address_2'] ); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_city"><?php _e( 'Town/City', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_city" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_city'] ) ) esc_attr_e( $_POST['billing_city'] ); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_postcode"><?php _e( 'Postal Code', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_postcode" id="reg_billing_postcode" value="<?php if ( ! empty( $_POST['billing_postcode'] ) ) esc_attr_e( $_POST['billing_postcode'] ); ?>" />
</p>
<div class="clear"></div>
<p class="form-row form-row-wide">
<label for="reg_billing_country"><?php _e( 'Country', 'woocommerce' ); ?> <span class="required">*</span></label>
<select class="country_select" name="billing_country" id="reg_billing_country">
<?php foreach ($countries as $key => $value): ?>
<option value="<?php echo $key?>"><?php echo $value?></option>
<?php endforeach; ?>
</select>
</p>
</fieldset>
<?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
To add Woocommerce Country/State fields in some other form use the following code in template:
<?php
$field = [
'type' => 'country',
'label' => 'Country',
'required' => 1,
'class' => ['address-field']
];
woocommerce_form_field( 'billing_country', $field, '' );
$field = [
'type' => 'state',
'label' => 'State',
'required' => 1,
'class' => ['address-field'],
'validate' => ['state']
];
woocommerce_form_field( 'billing_state', $field, '' );
?>
To tie the Country field selection with State field options put these fields into some container with class woocommerce-billing-fields AND include woocommerce country-select.js at page with the form:
<?php
$handle = 'wc-country-select';
wp_enqueue_script($handle, get_site_url().'/wp-content/plugins/woocommerce/assets/js/frontend/country-select.min.js', array('jquery'), true);
?>
Maybe it's too late but :
Instead of :
<p class="form-row form-row-wide">
<label for="reg_billing_country"><?php _e( 'Country', 'woocommerce' ); ?> <span class="required">*</span></label>
<select class="country_select" name="billing_country" id="reg_billing_country">
<?php foreach ($countries as $key => $value): ?>
<option value="<?php echo $key?>"><?php echo $value?></option>
<?php endforeach; ?>
</select>
</p>
place :
<?php
$countries_obj = new WC_Countries();
$countries = $countries_obj->get_allowed_countries();
woocommerce_form_field('billing_country', array(
'type' => 'select',
'class' => array( 'chzn-drop' ),
'label' => __('Pays'),
'placeholder' => __('Sélectionnez un pays'),
'options' => $countries
)
); ?>
You'll get a select dropdown of allowed countries
If you want a list of all countries, replace "get_allowed_countries();" by "__get('countries');"
Source
States are treated in this source

Yii2 radio button validation is not working

I have a form with multiple reference for a class(I mean table) in single form like add more details. Main goal of the task is a company have more than one users. each user have some access restrictions. so while adding company we will add multiple company users. company users form have that access radio button. here radio button validation is not working. same issue for checkbox and dropdown also.sample code given below. Please help.
AccessController.php
class AccessController extends Controller
{
public function actionCreate() {
$formDetails = Yii::$app->request->post('ClientAllowAccess', []);
if(!empty($formDetails)){
foreach ($formDetails as $i => $formDetail) {
$modelDetail = new ClientAllowAccess(['scenario' => ClientAllowAccess::SCENARIO_BATCH_UPDATE]);
$modelDetail->setAttributes($formDetail);
$modelClientAccess[] = $modelDetail;
}
} else {
$modelClientAccess[] = new ClientAllowAccess(['scenario' => ClientAllowAccess::SCENARIO_BATCH_UPDATE]);
}
return $this->render('create', [
'client_allow_access_multiple' => $modelClientAccess
]);
}
}
create.php
....
<?php foreach($client_allow_access_multiple as $i => $client_allow_acces): ?>
<?= $form->field($client_allow_access, '[$i]access_type')->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'],[ 'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
$return .= '<input type="radio" name="' . $name . '" value="' . $value . '" id="custom_id_value_'.$index.'" >';
$return .= '<span> ' . ucwords($label) . '</span>';
$return .= '</label>';
return $return;
}]); ?>
<?php endforeach; ?>
....
rendered view
<div class="form-group field-clientcontactdetails-0-gender has-success">
<label class="control-label" for="clientcontactdetails-0-gender">Gender</label>
<select id="clientcontactdetails-0-gender" class="form-control" name="ClientContactDetails[0][gender]">
<option value="">---</option>
<option value="1">Male</option>
<option value="2">Female</option>
<option value="3">Others</option>
</select>
<div class="help-block"></div>
</div>
<div class="form-group field-clientallowaccess-0-access_type required">
<label class="control-label" for="clientallowaccess-0-access_type">Access Type</label>
<input type="hidden" name="ClientAllowAccess[0][access_type]" value=""><div id="clientallowaccess-0-access_type"><label><input type="radio" name="ClientAllowAccess[0][access_type]" value="1"> Allow access</label>
<label><input type="radio" name="ClientAllowAccess[0][access_type]" value="2"> Can't allow access</label></div>
<div class="help-block"></div>
</div>

Update multiple rows with same id using foreach loop

I echo 2 input-fields (2 db columns) foreach row in the database (where id=$id) with each row's data being inside the input field. Admin-user can change data inside input-field and click update.
Currently, when clicking the update-button, it does update the rows (where id=$id) but it updates each row with the input-data of the first input field instead of updating input-data foreach input field. Thank you in advance for help.
view:
<form action='<?= site_url("admin/do_edit_page"); ?>' method='POST'>
<?php foreach($link_data as $row) : ?>
Link:<br />
<input type='text' name='page_link_title' value='<?= $row->link_title; ?>'>
<input type='text' name='page_link_sub_title' value='<?= $row->link; ?>'><br />
<?php endforeach; ?>
<input type='submit' name='update_site' value='Update'>
</form>
controller:
public function do_edit_page(){
$id = $this->input->post('page_id', TRUE);
$this->content_model->update_links($id);
}
model:
public function update_links($id){
foreach($_POST as $update_rows){
$update_rows = array(
array(
'page_id' => $id,
'link_title' => $this->input->post('page_link_title', TRUE),
'link' => $this->input->post('page_link_sub_title', TRUE)
)
);
$this->db->update_batch('content_links', $update_rows, 'page_id');
}
}
you have to move your form tag between the foreach loop so that it can submit the data of single row. something like this
<?php foreach($link_data as $row) : ?>
<form action='<?= site_url("admin/do_edit_page"); ?>' method='POST'>
Link:<br />
<input type='text' name='page_link_title' value='<?= $row->link_title; ?>'>
<input type='text' name='page_link_sub_title' value='<?= $row->link; ?>'><br />
<input type='submit' name='update_site' value='Update'>
</form>
<?php endforeach; ?>

I am creating a recent posts widgets for practice but I need help correctly making it so admin can adjust the category displayed

So like I said in the title, I am creating a recent posts widget for practice. It includes different features and the one that I am having problems with it is allowing admin to choose the category they want to display. I currently have it set up so that in the form it has a text field in which the admin can input the category manually but I need it to be such that it has a drop down menu that already has the category there, so the admin can just select it. I am not sure how to do this at all so if I could get some help that would be great. Sorry if I am being vague, I am new to this. I am posting my code below.
<?php
/*
Plugin Name: News Recent Posts Widget
Plugin URI:
Description: A recent post widget with extra functions that allow admin to make changes to certain values
Author: Kevin Ullyott
Version: 1.0
Author URI: http://modmacro.com/
*/
class recentpost extends WP_Widget {
public function __construct() {
parent::WP_Widget(
// or parent::__construct(
false,
'Kevin - Recent Posts Widget',
array(
'description' => __('A recent post widget with extra functions that allow admin to make changes to certain values')
)
);
;
}
public function widget( $args, $instance ) {
extract( $args );
$headline = $instance['headline'];
$category = $instance['category'];
$numberposts = $instance['numberposts'];
$readmore = $instance['readmore'];
echo $before_widget;
echo $before_title;
echo "<p class=\"headline\">$headline</p>";
echo $after_title;
$args = array( 'numberposts' => $numberposts, 'category_name' => $category );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
setup_postdata(get_post($recent['ID']));
echo '<a href="' . get_permalink($recent['ID']) . '" title=" '.esc_attr(get_the_title($recent['ID'])).'" >' . get_the_title($recent['ID']).'</a> ';
echo get_the_time('F j, Y', $recent['ID']);
the_excerpt();
}
wp_reset_postdata();
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['headline'] = ( $new_instance['headline'] );
$instance['category'] = ( $new_instance['category'] );
$instance['numberposts'] = ( $new_instance['numberposts'] );
$instance['readmore'] = ( $new_instance['readmore'] );
return $instance;
}
public function form( $instance ) {
$headline = $instance[ 'headline' ];
$category = $instance[ 'category' ];
$numberposts = $instance[ 'numberposts' ];
$readmore = $instance[ 'readmore' ];
?>
<p>
<label for="<?php echo $this->get_field_id( 'headline' ); ?>">
<?php _e( 'Headline:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'headline' ); ?>" name="<?php echo $this->get_field_name( 'headline' ); ?>" type="text" value="<?php echo esc_attr( $headline ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'category' ); ?>">
<?php _e( 'Category:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo esc_attr( $category ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'numberposts' ); ?>">
<?php _e( 'Number of posts:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'numberposts' ); ?>" name="<?php echo $this->get_field_name( 'numberposts' ); ?>" type="text" value="<?php echo esc_attr( $numberposts ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'readmore' ); ?>">
<?php _e( 'Read More:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'readmore' ); ?>" name="<?php echo $this->get_field_name( 'readmore' ); ?>" type="text" value="<?php echo esc_attr( $readmore ); ?>" />
</p>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("recentpost");') );
?>
The function wp_dropdown_categories will bring in the categories but adding the function alone wont save or retrieve the selected category. You'll need to add the name selected and id arguments. This should work I think:
<?php wp_dropdown_categories(array('name' => $this->get_field_name('category'), 'selected' => $category, 'id' => $this->get_field_id('category'), 'class' => 'widefat')); ?>
I added class widefat as well but its only for presentation. Hope that helps.
The function wp_dropdown_categories displays a dropdown menu that pulls in all of the categories used in the site. Here is the documentation on it: http://codex.wordpress.org/Function_Reference/wp_dropdown_categories
So you can replace
get_field_id( 'category' ); ?>" name="get_field_name( 'category' ); ?>" type="text" value="" />
with a call to the wp_dropdown_categories function.