Link to home
Start Free TrialLog in
Avatar of dthardy
dthardyFlag for United States of America

asked on

Auto submit wordpress admin form

I have a wordpress form from a custom theme that I have to submit daily.  I would like to automate this somehow.

The form is a simple input type="file" with a submit button.  The form id="import-upload-form" and the action="admin.php?page=app-importer&step=1&_wpnonce=2f4b58c58b".

I would like to :

a: insert the value for input type="file" (can be static or dynamic)
b: automatically submit the form once daily

Is this possible?

I have enclosed the key element of the source for the admin page with the sitename changed for security purposes.  If you need additional information please do not hesitate to tell me what you need in the comments.

I appreciate your help in advance.

<!DOCTYPE html>
<!--[if IE 8]>
<html xmlns="" class="ie8"  dir="ltr" lang="en-US" xmlns:og="" xmlns:fb="">
<!--[if !(IE 8) ]><!-->
<html xmlns=""  dir="ltr" lang="en-US" xmlns:og="" xmlns:fb="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CSV Importer WordPress</title>
<script type="text/javascript">
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
var userSettings = {
		'url': '/',
		'uid': '1',
	ajaxurl = '',
	pagenow = 'clipper_page_app-importer',
	typenow = '',
	adminpage = 'clipper_page_app-importer',
	thousandsSeparator = ',',
	decimalPoint = '.',
	isRtl = 0;

<script type="text/javascript">
var loadAjaxUpload = function() {
        var clickedObject = jQuery(this);

        var clickedID = jQuery(this).attr('id');
        new AjaxUpload(clickedID, {
                  action: '',
                  name: clickedID, // File upload name
                  data: { // Additional data to send
                                action: 'smart_ajax_post_action',
                                type: 'upload',
                                data: clickedID
                                                                , page: 'admin.php' },
                  autoSubmit: true, // Submit file after selection
                  responseType: 'json',
                  onChange: function(file, extension){},
                  onSubmit: function(file, extension){
                          if (! (extension && /^(jpg|png|jpeg|gif)$/i.test(extension))){
              // extension is not allowed
              alert('Error: invalid file extension');
              // cancel upload
              return false;
                                jQuery('#uploadtext_'+clickedID).text('Uploading'); // change button text, when user selects file	
                                this.disable(); // If you want to allow uploading only 1 file at time, you can disable upload button
                                interval = window.setInterval(function(){
                                        var text = jQuery('#uploadtext_'+clickedID).text();
                                        if (text.length < 13){	
                                                jQuery('#uploadtext_'+clickedID).text(text + '.'); 
                                        else { 
                                }, 200); 
                  onComplete: function(file, response) {
                        this.enable(); // enable upload button

                        // If there was an error
                        if(response.error ){
                                var buildReturn = '<span class="upload-error">' + response.error + '</span>';
                                var isSlider = jQuery("#" + clickedID + "_type").val();
                                if(isSlider != 'upload') { 
                                        var buildReturn = '<img class="smartBreadcrumbsPreviewThumb" id="image_'+clickedID+'" src="'+response.url+'&w=120&h=60&zc=1" />';
                                        jQuery("#reset_" + clickedID).show();
                                        jQuery("#uploaded_image_" + clickedID).attr("href",response.url);
                                        jQuery("#uploaded_image_" + clickedID).html(buildReturn);
                                        jQuery("#image_" + clickedID).fadeIn();
                                        jQuery("#uploaded_image_" + clickedID).fadeIn();

                                if(isSlider == 'upload') 
                                        //multi file add
                                        // add file to the list

                                        var CounFiles = jQuery("." + clickedID + "_img_count").val();
                                        jQuery("." + clickedID + "_img_count").val(CounFiles);

                                        var ImgDetails = '<input type="hidden" name="'+clickedID+'_sliderdata['+CounFiles+'][img]" value="'+response.url+'" />';
                                        ImgDetails += '<table class="added_image"><tr><td width="60px" valign="top">';
                                        ImgDetails += '<img src="'+response.url+'&w=120&h=60&zc=1" target="_blank" alt="" />';
                                        ImgDetails += '</td><td valign="top">';
                                        ImgDetails += '<div>' + file + '</div>';

                                        for ( var i in response.fields.fields )
                                                var field = response.fields.fields[i]; 
                                                var field_id = field['id'];
                                                var field_std = field['std'];
                                                var field_desc = field['desc'];

                                                if(field['type'] == 'text') {
                                                        ImgDetails += '<div><input type="text" name="'+clickedID+'_sliderdata['+CounFiles+']['+field_id+']" value="' + field_std + '" class="slider_text slider_'+field_id+'" title="'+field_desc+'"  /></div>';  
                                                } else if (field['type'] == 'textarea') {
                                                        ImgDetails += '<div><textarea name="'+clickedID+'_sliderdata['+CounFiles+']['+field_id+']" class="slider_textarea slider_'+field_id+'" title="'+field_desc+'" >' + field_std + '</textarea></div>';  
                                                } else if (field['type'] == 'select') {
                                                        ImgDetails += '<div><select name="'+clickedID+'_sliderdata['+CounFiles+']['+field_id+']" class="slider_select slider_'+field_id+'" >';

                                                        for ( var key in field['options'] )
                                                                var selected = '';
                                                                if(key == field_std) selected = ' selected="selected"';
                                                                ImgDetails += '<option '+ selected +' value="' + key + '" >' + field["options"][key] + '</option>';
                                                        ImgDetails += '</select></div>';  

                                        ImgDetails += '</td></tr></table>';

                                        var FilesList = jQuery('#files_' + clickedID );
                                        jQuery('<li class="ui-state-default"></li>').prependTo(FilesList).html(ImgDetails);



        var clickedObject = jQuery(this);
        var clickedID = jQuery(this).attr('id');
        var theID = jQuery(this).attr('title');				

        var ajax_url = '';

        var data = {
                action: 'smart_ajax_post_action',
                type: 'image_reset',
                data: theID
                        };, data, function(response) {
                var image_to_remove = jQuery('#image_' + theID);
                var button_to_hide = jQuery('#reset_' + theID);
                image_to_remove.fadeOut(500,function(){ jQuery(this).remove(); });

        return false; 

<body class="wp-admin no-js  clipper_page_app-importer admin-bar branch-3-3 version-3-3-1 admin-color-fresh">
<script type="text/javascript">document.body.className = document.body.className.replace('no-js','js');</script>

<div id="wpwrap">

<div id="adminmenuback"></div>
<div id="adminmenuwrap">

<div id="wpcontent">

<div id="wpbody">

<div id="wpbody-content">
		<div id="screen-meta" class="metabox-prefs">

			<div id="contextual-help-wrap" class="hidden no-sidebar">
				<div id="contextual-help-back"></div>
				<div id="contextual-help-columns">
					<div class="contextual-help-tabs">

					<div class="contextual-help-tabs-wrap">
		<div class='update-nag'><a href="">WordPress 3.3.2</a> is available! <a href="">Please update now</a>.</div><div class="updated fade"><p>One or more plugins have been activated or deactivated, please <input type="button" class="button " value="empty the page cache" onclick="document.location.href='admin.php?page=w3tc_general&amp;w3tc_flush_pgcache&amp;_wpnonce=5e5bdecc2a';" /> and check the <input type="button" class="button " value="minify settings" onclick="document.location.href='admin.php?page=w3tc_general&amp;w3tc_hide_note&amp;note=plugins_updated&amp;redirect=admin.php%3Fpage%3Dw3tc_minify&amp;_wpnonce=5e5bdecc2a';" /> to maintain the desired user experience. <input type="button" class="button " value="Hide this message" onclick="document.location.href='admin.php?page=w3tc_general&amp;w3tc_hide_note&amp;note=plugins_updated&amp;_wpnonce=5e5bdecc2a';" /></p></div><div class='wrap'>
<div id="icon-tools" class="icon32"><br /></div><h2>CSV Importer</h2>
<div class="narrow"><p>Below you will find a tool which allows you to import content from other systems via a CSV (comma-separated values) file, which can be edited using a program like Excel. Note that the file must be in the correct format for the import tool to work. You will find an example .csv file in the "examples" theme folder.</p><p>Choose a CSV file to upload, then click "Upload file and import".</p><form enctype="multipart/form-data" id="import-upload-form" method="post" action="admin.php?page=app-importer&amp;step=1&amp;_wpnonce=2f4b58c58b">
<label for="upload">Choose a file from your computer:</label> (Maximum size: 8MB)
<input type="file" id="upload" name="import" size="25" />
<input type="hidden" name="action" value="save" />
<input type="hidden" name="max_file_size" value="8388608" />
<p class="submit"><input type="submit" name="submit" id="submit" class="button" value="Upload file and import"  /></p></form>

<div class="clear"></div></div><!-- wpbody-content -->
<div class="clear"></div></div><!-- wpbody -->
<div class="clear"></div></div><!-- wpcontent -->

<div id="footer">
<p id="footer-left" class="alignleft"><span id="footer-thankyou">Thank you for creating with <a href="">WordPress</a>.</span></p>
<p id="footer-upgrade" class="alignright"><strong><a href="">Get Version 3.3.2</a></strong></p>
<div class="clear"></div>

<script type='text/javascript'>
/* <![CDATA[ */
var commonL10n = {"warnDelete":"You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete."};/* ]]> */
<script type='text/javascript' src=';load=admin-bar,hoverIntent,common,jquery-color,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,postbox,jquery-ui-tabs,jquery-form&amp;ver=a0633d29cb77c0c521f0e7006128a7d1'></script>

<div class="clear"></div></div><!-- wpwrap -->
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>

Open in new window

Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dthardy


Is there a way to do this with out the use of the form?

Possibly have the file stored on the server locally and run the installer via a script?

Any ideas how to do this?