• I created a custom template in the theme Flexform. In this template I display the users details and provide a option for the user to upload a profile picture and then also edit their details. Thus the page has two form submit buttons. line 229 to 232 is the form for the upload profile picture option and lines 164 to 203 is the code that executes that submission. Then lines from 256 to 281 is for the update form submission and code on lines 204 to 207 is where that should execute. When uploading a image it works fine, but when I press the update button it gives a 404 error.

    My code is as follows:

    <?php
    /*
    Template Name: Users
    */
    get_header(); ?>

    <script type='text/javascript'>
    function showDiv() {
    document.getElementById('textdetails').style.display = "none";
    document.getElementById('formdetails').style.display = "block";
    }
    function showDiv2() {
    document.getElementById('textdetails').style.display = "block";
    document.getElementById('formdetails').style.display = "none";
    }
    </script>

    <?php
    $options = get_option('sf_flexform_options');

    $default_show_page_heading = $options['default_show_page_heading'];
    $default_page_heading_bg_alt = $options['default_page_heading_bg_alt'];
    $default_sidebar_config = $options['default_sidebar_config'];
    $default_left_sidebar = $options['default_left_sidebar'];
    $default_right_sidebar = $options['default_right_sidebar'];

    $show_page_title = get_post_meta($post->ID, 'sf_page_title', true);
    $page_title_one = get_post_meta($post->ID, 'sf_page_title_one', true);
    $page_title_two = get_post_meta($post->ID, 'sf_page_title_two', true);
    $page_title_bg = get_post_meta($post->ID, 'sf_page_title_bg', true);

    if ($show_page_title == "") {
    $show_page_title = $default_show_page_heading;
    }
    if ($page_title_bg == "") {
    $page_title_bg = $default_page_heading_bg_alt;
    }

    $sidebar_config = get_post_meta($post->ID, 'sf_sidebar_config', true);
    $left_sidebar = get_post_meta($post->ID, 'sf_left_sidebar', true);
    $right_sidebar = get_post_meta($post->ID, 'sf_right_sidebar', true);

    if ($sidebar_config == "") {
    $sidebar_config = $default_sidebar_config;
    }
    if ($left_sidebar == "") {
    $left_sidebar = $default_left_sidebar;
    }
    if ($right_sidebar == "") {
    $right_sidebar = $default_right_sidebar;
    }

    $page_wrap_class = '';
    if ($sidebar_config == "left-sidebar") {
    $page_wrap_class = 'has-left-sidebar has-one-sidebar row';
    } else if ($sidebar_config == "right-sidebar") {
    $page_wrap_class = 'has-right-sidebar has-one-sidebar row';
    } else if ($sidebar_config == "both-sidebars") {
    $page_wrap_class = 'has-both-sidebars';
    } else {
    $page_wrap_class = 'has-no-sidebar';
    }

    $remove_breadcrumbs = get_post_meta($post->ID, 'sf_no_breadcrumbs', true);
    $remove_bottom_spacing = get_post_meta($post->ID, 'sf_no_bottom_spacing', true);
    $remove_top_spacing = get_post_meta($post->ID, 'sf_no_top_spacing', true);

    if ($remove_bottom_spacing) {
    $page_wrap_class .= ' no-bottom-spacing';
    }
    if ($remove_top_spacing) {
    $page_wrap_class .= ' no-top-spacing';
    }
    ?>

    <?php if (have_posts()) : the_post(); ?>

    <?php if ($show_page_title) { ?>
    <div class="row">
    <div class="page-heading span12 clearfix alt-bg <?php echo $page_title_bg; ?>">
    <?php if ($page_title_one || $page_title_two) { ?>
    <h1><?php echo $page_title_one; ?></h1>
    <h3><?php echo $page_title_two; ?></h3>
    <?php } else { ?>
    <h1><?php the_title(); ?></h1>
    <?php } ?>
    </div>
    </div>
    <?php } ?>

    <?php
    // BREADCRUMBS
    if(!$remove_breadcrumbs) {
    echo sf_breadcrumbs();
    } ?>

    <div class="inner-page-wrap <?php echo $page_wrap_class; ?> clearfix">

    <!-- OPEN page -->
    <?php if (($sidebar_config == "left-sidebar") || ($sidebar_config == "right-sidebar")) { ?>
    <div <?php post_class('clearfix span8'); ?> id="<?php the_ID(); ?>">
    <?php } else if ($sidebar_config == "both-sidebars") { ?>
    <div <?php post_class('clearfix row'); ?> id="<?php the_ID(); ?>">
    <?php } else { ?>
    <div <?php post_class('clearfix'); ?> id="<?php the_ID(); ?>">
    <?php } ?>

    <?php if ($sidebar_config == "both-sidebars") { ?>

    <div class="page-content span6">
    <?php the_content(); ?>
    </div>

    <aside class="sidebar left-sidebar span3">
    <?php dynamic_sidebar($left_sidebar); ?>
    </aside>

    <?php } else { ?>

    <div class="page-content clearfix">

    <?php the_content(); ?>

    <?php
    $current_user = wp_get_current_user();
    $sql = "SELECT * FROM wp_users WHERE ID = 1 LIMIT 0, 30 “;
    $query = “SELECT * FROM wp_users WHERE ID = “.$current_user->ID.” LIMIT 0, 30 “;
    $query2 = “SELECT * FROM user_details WHERE user_id = “.$current_user->ID.” LIMIT 0, 30 “;
    global $wpdb;
    $user = $wpdb->get_row($query);
    $userdetails = $wpdb->get_row($query2);
    $female = “<option value=’female’>”;
    $male = “<option value=’male’>”;
    $white = “<option value=’white’>”;
    $african = “<option value=’african’>”;
    $coloured = “<option value=’coloured’>”;
    $asian = “<option value=’asian’>”;
    $other = “<option value=’other’>”;
    if($userdetails->user_gender==”female”){
    $female = “<option value=’female’ selected=’selected’>”;
    }
    else
    {
    $male = “<option value=’male’ selected=’selected’>”;
    }
    if($userdetails->user_race==”white”){
    $female = “<option value=’white’ selected=’selected’>”;
    }
    if($userdetails->user_race==”african”){
    $female = “<option value=’african’ selected=’selected’>”;
    }
    if($userdetails->user_race==”coloured”){
    $female = “<option value=’coloured’ selected=’selected’>”;
    }
    if($userdetails->user_race==”asian”){
    $female = “<option value=’asian’ selected=’selected’>”;
    }
    if($userdetails->user_race==”other”){
    $female = “<option value=’other’ selected=’selected’>”;
    }

    if($_POST[‘submit’] == ‘Submit’)
    {
    if(isset($_FILES[‘upload’]))
    {
    //upload refers to form element “upload”
    $allowed = array (‘image/pjpeg’, ‘image/jpeg’, ‘image/JPG’, ‘image/X-PNG’, ‘image/PNG’, ‘image/png’, ‘image/GIF’);
    if(in_array($_FILES[‘upload’][‘type’], $allowed))
    {
    //if upload if in the allowed file types

    //move the file over
    if(move_uploaded_file($_FILES[‘upload’][‘tmp_name’], “C:\\wamp\\www\\HRTestSite\\wp-content\\uploads\\2014\1\\{$_FILES[‘upload’][‘name’]}”))
    {
    //moveuf method moves to tmp folder then moves to final location

    $image=”{$_FILES[‘upload’][‘name’]}”;
    print “$image”;
    }//end of moving DAT IMG :3
    else
    {
    if($FILES[‘upload’][‘error’] > 0)
    {

    }
    }
    if(file_exists($_FILES[‘upload’][‘tmp_name’]) && is_file($_FILES[‘upload’][‘tmp_name’]))
    {
    unlink($_FILES[‘upload’][‘tmp_name’]);
    }
    $query3 = “UPDATE user_details SET user_picture = ‘http://localhost/HRTestSite/wp-content/uploads/2014/01/&#8221;.$image.”‘ WHERE ID =”.$current_user->ID;

    $wpdb->query($query3);
    echo ‘
    <script type=”text/javascript”>
    parent.window.location.reload(true);
    </script>
    ‘;
    }
    }
    }
    if($_POST[‘update’] == ‘Update’)
    {
    echo “some script must execute here”;
    }

    if(strlen($userdetails->user_picture) == 0)
    {
    $picurl = “http://localhost/HRTestSite/wp-content/uploads/2014/01/Placeholder-profile.png&#8221;;
    }
    else
    {
    $picurl = $userdetails->user_picture;
    }

    echo do_shortcode(‘[vc_tabs][vc_tab title=”Summary”]
    [vc_column_text]Summary of everything[/vc_column_text][/vc_tab]
    [vc_tab title=”Profile”]

    [vc_column_text]
    [printfriendly]
    <h1>Profile</h1>
    <img src=”‘.$picurl.'” width=”200px” height=”200px”/>
    <form method=”post” enctype=”multipart/form-data”>
    <input type=”file” name=”upload” id=”upload”>
    <input type=”submit” name=”submit” value=”Submit”>
    </form>
    <h3>User Information</h3><div id=”textdetails”>

    [one_fourth]Name:[/one_fourth][one_fourth]’.$userdetails->user_name.'[/one_fourth]

    [one_fourth]Surname:[/one_fourth][one_fourth]’.$userdetails->user_surname.'[/one_fourth]
    [one_fourth]User Name:[/one_fourth][one_fourth]’.$user->user_login.'[/one_fourth]

    [one_fourth]Display Name:[/one_fourth][one_fourth]’.$user->display_name.'[/one_fourth]

    [one_fourth]Date Registered:[/one_fourth][one_fourth]’.$user->user_registered.'[/one_fourth]
    [one_fourth]Race:[/one_fourth][one_fourth]’.$userdetails->user_race.'[/one_fourth]
    [one_fourth]Gender:[/one_fourth][one_fourth]’.$userdetails->user_gender.'[/one_fourth]

    [divider type=”standard”]
    <h3>Contact Information</h3>
    [one_fourth]Address:[/one_fourth][one_fourth]’.$userdetails->user_address_line_1.'[/one_fourth]
    [one_fourth] [/one_fourth][one_fourth]’.$userdetails->user_address_line_2.'[/one_fourth]
    [one_fourth] [/one_fourth][one_fourth]’.$userdetails->user_address_city.'[/one_fourth]
    [one_fourth] [/one_fourth][one_fourth]’.$userdetails->user_address_code.'[/one_fourth]
    [one_fourth]Tel Number:[/one_fourth][one_fourth]’.$userdetails->user_tel_num.'[/one_fourth]
    [one_fourth]Fax Number:[/one_fourth][one_fourth]’.$userdetails->user_fax_num.'[/one_fourth]
    [one_fourth]Email:[/one_fourth][one_fourth]’.$user->user_email.'[/one_fourth]
    [one_fourth]Alternative Email:[/one_fourth][one_fourth]’.$userdetails->user_alt_email.'[/one_fourth]
    <div style=”text-align: right; color: red;”>Edit</div></div>
    <div id=”formdetails” style=”display:none;”>
    <form method=”post” action=””>
    [one_fourth]Name:[/one_fourth][one_fourth]<input type=”text” name=”name” value=”‘.$userdetails->user_name.'”>[/one_fourth]

    [one_fourth]Surname:[/one_fourth][one_fourth]<input type=”text” name=”surname” value=”‘.$userdetails->user_surname.'”>[/one_fourth]

    [one_fourth]User Name:[/one_fourth][one_fourth]<input type=”text” name=”username” value=”‘.$user->user_login.'”>[/one_fourth]

    [one_fourth]Display Name:[/one_fourth][one_fourth]<input type=”text” name=”displayname” value=”‘.$user->display_name.'”>[/one_fourth]

    [one_fourth]Gender:[/one_fourth][one_fourth]<select name=”gender”>’.$female.’Female</option>
    ‘.$male.’Male</option></select>[/one_fourth]

    [one_fourth]Gender:[/one_fourth][one_fourth]
    <select name=”race”>’.$white.’White</option>
    ‘.$african.’African</option>
    ‘.$coloured.’Coloured</option>
    ‘.$asian.’Asian</option>
    ‘.$other.’Other</option></select>[/one_fourth]

    [divider type=”standard”]
    <h3>Contact Information</h3>
    [one_fourth]Address:[/one_fourth][one_fourth]<input type=”text” name=”address1″ value=”‘.$userdetails->user_address_line_1.'”>[/one_fourth]

    [one_fourth] [/one_fourth][one_fourth]<input type=”text” name=”address2″ value=”‘.$userdetails->user_address_line_2.'”>[/one_fourth]

    [one_fourth] [/one_fourth][one_fourth]<input type=”text” name=”city” value=”‘.$userdetails->user_address_city.'”>[/one_fourth]

    [one_fourth] [/one_fourth][one_fourth]<input type=”text” name=”code” value=”‘.$userdetails->user_address_code.'”>[/one_fourth]

    [one_fourth]Tel Number:[/one_fourth][one_fourth]<input type=”text” name=”tel” value=”‘.$userdetails->user_tel_num.'”>[/one_fourth]

    [one_fourth]Fax Number:[/one_fourth][one_fourth]<input type=”text” name=”fax” value=”‘.$userdetails->user_fax_num.'”>[/one_fourth]

    [one_fourth]Email:[/one_fourth][one_fourth]<input type=”text” name=”email” value=”‘.$user->user_email.'”>[/one_fourth]

    [one_fourth]Alternative Email:[/one_fourth][one_fourth]<input type=”text” name=”aemail” value=”‘.$userdetails->user_alt_email.'”>[/one_fourth]

    <div style=”text-align:right;”><input type=”submit” name=”update” value=”Update”>
    <button type=”button” onclick=”showDiv2()”>Cancel</button></div>
    </form>
    </div>
    [/vc_tab][vc_tab title=”Standard Tab Three”]
    [vc_column_text]Lorem ipsum dolor sit amet, consectetur adipiscing elit…[/vc_column_text]
    [/vc_tab]
    [/vc_tabs]’);
    //}

    // if($_POST[‘update’] != ”)
    // {

    // echo “string”;
    // $query4 = “UPDATE user_details SET user_race='”.$_POST[‘race’].”‘,user_gender='”.$_POST[‘gender’].”‘,user_address_line_1='”.$_POST[‘address1’].”‘,user_address_line_2='”.$_POST[‘address2’].”‘,user_address_city='”.$_POST[‘city’].”‘,user_address_code=”.$_POST[‘code’].”,user_tel_num='”.$_POST[‘tel’].”‘,user_fax_num='”.$_POST[‘fax’].”‘,user_alt_email='”.$_POST[‘aemail’].”‘,user_name='”.$_POST[‘name’].”‘,user_surname='”.$_POST[‘surname’].”‘ WHERE ID =”.$current_user->ID;
    // $query5 = “UPDATE wp_users SET user_login='”.$_POST[‘username’].”‘, user_email='”.$_POST[’email’].”‘, display_name='”.$_POST[‘displayname’].”‘ WHERE ID=”.$current_user->ID;

    // $wpdb->query($query4);
    // $wpdb->query($query5);

    // }

    ?>

    </div>

    <?php } ?>

    <!– CLOSE page –>
    </div>

    <?php if ($sidebar_config == “left-sidebar”) { ?>

    <aside class=”sidebar left-sidebar span4″>
    <?php dynamic_sidebar($left_sidebar); ?>
    </aside>

    <?php } else if ($sidebar_config == “right-sidebar”) { ?>

    <aside class=”sidebar right-sidebar span4″>
    <?php dynamic_sidebar($right_sidebar); ?>
    </aside>

    <?php } else if ($sidebar_config == “both-sidebars”) { ?>

    <aside class=”sidebar right-sidebar span3″>
    <?php dynamic_sidebar($right_sidebar); ?>
    </aside>

    <?php } ?>

    </div>

    <?php endif; ?>

    <!–// WordPress Hook //–>
    <?php get_footer(); ?>

  • The topic ‘PHP Form Submit’ is closed to new replies.