Last active
March 13, 2019 04:38
-
-
Save yasaryousuf/463114e6bc20436f33572778839f234c to your computer and use it in GitHub Desktop.
[WP FORM]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$OpsState = new OpsState; | |
$results = $OpsState->index(); | |
?> | |
<div class="bootstrap-wrapper"> | |
<form class="" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="POST"> | |
<input type="hidden" name="action" value="update_states_link"> | |
<?php wp_nonce_field('updateStatesLink-nonce', 'updateStatesLink');?> | |
<div class="row"> | |
<?php foreach($results as $result): ?> | |
<div class="col-sm-4"> | |
<div class="form-group"> | |
<input class="form-control" type="text" name="data[<?php echo $result->id; ?>][state]" value="<?php echo $result->name; ?>"> | |
<input class="form-control" type="hidden" name="data[<?php echo $result->id; ?>][id]" value="<?php echo $result->id; ?>"> | |
</div> | |
</div> | |
<div class="col-sm-8"> | |
<div class="form-group"> | |
<input class="form-control" type="text" name="data[<?php echo $result->id; ?>][link]" value="<?php echo $result->link; ?>"> | |
</div> | |
</div> | |
<?php endforeach; ?> | |
<div class="form-group"> | |
<div class="col-sm-12"> | |
<button type="submit" class="btn btn-primary form-control">Submit</button> | |
</div> | |
</div> | |
</div> | |
</form> | |
</div> | |
// in action.php | |
<?php | |
public static function init() | |
{ | |
$self = new self; | |
//add_action('admin_post_', array($self,'') ); | |
//add_action('admin_post_nopriv_', array($self,'') ); | |
add_action('admin_post_get_events_by_year', array($self,'getEventsByYear') ); | |
add_action('admin_post_update_event', array($self,'updateEvent') ); | |
add_action('admin_post_add_states', array($self,'addStates') ); | |
add_action('admin_post_update_states_link', array($self, 'updateStatesLink')); | |
} | |
public function updateStatesLink() | |
{ | |
if (!isset($_POST['UpdateMailChimpAPI']) || !wp_verify_nonce($_POST['UpdateMailChimpAPI'], 'UpdateMailChimpAPI-nonce')) { | |
die("You are not allowed to submit data."); | |
} | |
echo '<pre>'; print_r($_POST); echo '</pre>'; | |
foreach($_POST['data'] as $result){ | |
$data['name'] = $result['state']; | |
$data['link'] = $result['link']; | |
$data['id'] = $result['id']; | |
$this->State->update($data); | |
wp_redirect($_POST['_wp_http_referer']); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment