• jimmyt1988

    (@jimmyt1988)


    Hi all,

      Background

    I’m creating my own form on a custom post called ‘cars’

      The set up

    I have 3 input boxes of type ‘file’…
    On submit, it will upload the images and put info into a database.

      The problem

    Problem is, when I press the submit button with the name’uploadImages’ it should run:

    if(isset($_POST['uploadImages'])){
    echo "hello";
    }

    but it doesn’t echo “hello”.

      The Question

    If you submit the wordpress post/page type forms, does it clear out any $_post data so that when the page comes back round, my script can’t run because it no longer knows that my submit button was pressed?

Viewing 15 replies - 1 through 15 (of 15 total)
  • If you submit the wordpress post/page type forms, does it clear out any $_post data so that when the page comes back round, my script can’t run because it no longer knows that my submit button was pressed?

    Basically, yes. When you submit the post form, WordPress processes all of the data using one script, then redirects back to the post screen once all of the processing is finished.

    Therefore, if you want to output some information upon submitting the form, you have two choices:

    1. You can use wp_die() to kill the script once the form is submitted, so you can see the information you’re trying to output
    2. You can add a query string parameter to the redirect so that you can then use it to find out what happened during the processing (you’ll notice that WordPress already adds a “message” parameter to the query string, which tells it whether any errors occurred or anything)
    Thread Starter jimmyt1988

    (@jimmyt1988)

    Ooo, thanks. I’ll get back to see if I have solved or not. Thanks for the info.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    Ok i’ve tried many things.. I don’t reall understand what the hell that wp_die() is for.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    I’m really stuck… It’s very irritating.

    I have a plugin file called cars.php and it is calling all the bits and bobs to make it a custom post type of ‘car’.

    This following bit of code calls the create form function which makes a form come up in the admin car post area:

    http://pastebin.com/kbwwQ7ZF

    Why when I press my own custom submit button, does it not call my php script?

    WTF?

    It echo’s A and C.. but not B.. EVEN THOUGH THE SQL is being run ???? If I edit the SQL part out.. the SQL doesnt run.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    On submit, if I do:

    if($_POST['uploadImages']){
            echo "bumtumbelleh";
        }

    It says:

    Notice: Undefined index: uploadImages in D:\InstallationFiles\wamp\www\classicandvintage.co.uk\wp-content\plugins\banner\cars.php on line 141

    HOW CAN IT BE UNDEFINED WHEN IM PRESSING THE SUBMIT BUTTON CALLED uploadImages returning it to the same page? *cries*

    Latest version of my mess: http://pastebin.com/NhckhAua

    Thread Starter jimmyt1988

    (@jimmyt1988)

    If I take my form and submit button outside of the function that is called by:

    add_action('admin_init', 'myplugin_add_gallery_cars', 1);

    Everything works absolutely perfectly. It’s just it is no longer within the admin module.

    Here is an image:
    http://jamestrusler.co.uk/files/helpme.jpg

    Thread Starter jimmyt1988

    (@jimmyt1988)

    Is it something i’m missing out on with this:

    <?php add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args ); ?>

    What is the callback_args for? Do I put all my scripting into a function then put the function here?

    Thread Starter jimmyt1988

    (@jimmyt1988)

    I think I know where the problem is…

    my function is being called:
    add_action('admin_init', 'myplugin_add_gallery_cars', 1);

    Basically, my form is being output via this so when the submit button I have made with the above add_action call is pressed, the post data:

    if($_POST['uploadImages']){
            echo "bumtumbelleh";
        }

    is being lost because it’s all being reinitialised on post.

    Is there a way to pass the function all of the POST data or to stop all the POST data being stripped out on submit?

    esmi

    (@esmi)

    I suggest you start looking at the Plugin API.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    register_activation_hook() ? I’ve tried lots of them, i’m confused. Mainly coz i’ve spent about 5 hours now on the same thing. I just want a sniff of victory if you know what the answer is.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    I’ve been trying:
    add_action ( ‘init’, ‘uploadFeatures’ );

    So that the form is output first, then the processing scripts are being processed before $_POST data has been cleared.. But it’s not working.

    Thread Starter jimmyt1988

    (@jimmyt1988)

    OMG HANGONG.. LOLLLL, OK this is progress. I managed to get inside my If statement by adding

    add_action ( 'init', 'uploadFeatures' );

    and correcting some syntax shizzle.

    Ill keep ye updated…

    *excited*

    Thread Starter jimmyt1988

    (@jimmyt1988)

    Grrr, still lost. I have been reading that god damn plugin api for a long time.

    Can i have a hint of which direction to take.

    add_action('admin_init', 'myplugin_add_gallery_cars', 1);
    add_action ( 'init', 'uploadFeatures' );

    myplugin_add_gallery_cars outputs the form into a new wordpress meta box.

    uploadFeatures is a function that runs through the file fields that are created by myplugin_add_gallery_cars when the submit button is pressed.

    The problem is that:
    if(isset($_POST['uploadImages'])){

    is not returning true and i just don’t know why.
    http://jamestrusler.co.uk/files/helpme.jpg

    esmi

    (@esmi)

    Try posting a new topic and I’ll move to WP-Advanced forum for you. Feel free to email me with a reminder to move the post as soon as it’s published in case I’ve logged off for the day.

    esmi

    (@esmi)

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘custom post submit button’ is closed to new replies.