• Resolved Miflon

    (@miflon)


    Hy everybody. My configuration:
    PHP/MySQL version: 7.0.11/5.6.32
    Theme in use: Techtime.
    Plugins in use: All In One WP Security(Version 4.1.5); Contact Form 7(Version 4.5);
    Really Simple CAPTCHA(Version 1.9); WordPress File Upload(Version 3.9.2).
    host name: o2switch.
    site address: Local for now.
    Issue encountered: Here is my code located in the template of a page

    <?php
    /**
     * Template Name: Ajouter licence, sans sidebar.
    */
    get_header(); ?>
    <div id="main-fullwidth">	
        <?php $theme->hook("main_before"); $theme->hook("content_before");
            global $wpdb;
            $id_membre=$_GET['ID'];
    //here lot of database queries
        ?>
    </div>
            <form id="form" method="POST" class="wpcf7-form" >
                <table style="width:85%;">
    <!-- Here rows end columns of the table -->
    		<th><input type="submit" value="Enregistrer" id="enregistrer" class="licence" name="enregistrer" style="cursor:pointer;font-weight:bold;font-size:100%;"></th>
    	     </table>
            </form>
    <?php if ( isset( $_POST['enregistrer'] ) ) {
    // Here data processing
    } ?>
    </div><!-- #main-fullwidth -->
    <?php get_footer(); ?>

    I would like at the end of the data processing returning to the homepage without the use of a button. Is it possible? I tried hopeless wp_redirect and as supposed it did’nt work.
    Can somebody points me in the right direction?
    Thanks in advance, Miflon.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @miflon,

    Do you get any errors on the page? Does the data processing part end successfully without any errors? In the code above I do not see anywp_redirect()function and hence I am curious to know how you have been using it. Are you calling “exit;” after wp_redirect() ?

    You could also achieve this via Javascript as shown below:
    https://stackoverflow.com/questions/20834906/wordpress-wp-redirect-not-redirecting

    The above page has some other options too. Hope that helps.

    Thread Starter Miflon

    (@miflon)

    @tanveer Sure, thanks for your reply.
    I take wp_redirect or wp__safe_redirect out of the code I submit. I did’nt forget to call “exit” after wp_redirect or wp__safe_redirect.
    Data processing ends successfully. I checked the result from the database.
    I get no error. The page reloads itself.
    I don’t know every thing about wordpress and I am wondering if there is a function, a hook or a plugin achieving that goal.
    I’ll take a look to the link you offer.
    Thanks again for your reply.

    Thread Starter Miflon

    (@miflon)

    I modify my code as below:

    <?php if ( isset( $_POST['modifier'] ) ) {
        // Here data update
        <strong>echo '<script type="text/javascript">window.location.href = "https://myhomepage/adherents/";</script>';</strong>
        } ?>
        </div><!-- #main-fullwidth -->
    <?php get_footer(); ?>

    This works but the page reloads itself with the initial values (before updating) and then jumps to the homepage. I query the database, the correct values are stored!
    Can I avoid the display of the page before reaching the homepage?
    Thanks for your replies.

    Hi @miflon,

    Not sure why it is jumping to the in-between page but are you sure it is just this part of code doing it and not anything above ?

    This part of the code should just point your browser to the homepage. Could you use a debugger locally and confirm?

    Thread Starter Miflon

    (@miflon)

    Hi @tsure.
    The javascript code works fine. The jump to the home page does the same issue with my other templates! It’s not a critical error but I would like to understand
    I bring to you the template code for seeking what’s going wrong:

    <?php
    /** Template Name: Modifier licence, sans sidebar */
    get_header(); ?>
      <div id="main-fullwidth">	
      <?php $theme->hook("main_before"); $theme->hook("content_before");
        global $wpdb;
        $id_membre= (integer) $_GET['ID'];
        $membre = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}t_e_membres_mbr WHERE mbr_id = $id_membre;" );
        $sql = "SELECT l.lcc_numero, f.fdt_code, f.fdt_id ";
        $sql = $sql . "FROM {$wpdb->prefix}t_j_licences_lcc l ";
        $sql = $sql . "INNER JOIN {$wpdb->prefix}t_r_federations_fdt f ";
        $sql = $sql . "ON l.fdt_id = f.fdt_id ";
        $sql = $sql . "WHERE l.mbr_id = $id_membre;";
        $licences = $wpdb->get_results( $sql );
        $n = 1;
        $nom_table_licences = $wpdb->prefix . 't_j_licences_lcc';
      ?>
      <div class="texte" style="margin-bottom:15px;"> 
        <h3>Modifier la ou les licence(s) de <?php echo $membre->mbr_prenom . " " . $membre->mbr_nom . " :" ?></h3>
      </div>
      <form id="form" method="POST" class="wpcf7-form" >
        <table style="width:50%;">
          <tr>
              <th style="text-align:right;">Fédération</th>
              <th style="text-align:left;">Licence n°</th>
          </tr>
          <?php foreach( $licences as $licence ) { ?>
          <tr>
    	  <td style="text-align:right;font-weight:bold;"><h5><?php echo $licence->fdt_code . " : " ?></h5></td>
    	  <td style="text-align:left;"><input id="numero" class="licence" name="numero<?php echo $n ?>" type="text" size="10" maxlength="10" value = "<?php echo $licence->lcc_numero ?>"></td>
          </tr>
        <?php $n++; } ?>
          <tr>
    	  <th></th>
    	  <th style="text-align:left;"><input type="submit" value="Modifier" id="modifier" class="licence" name="modifier" style="cursor:pointer;font-weight:bold;font-size:100%;"></th>
          </tr>
        </table>
      </form>
      <?php if ( isset( $_POST['modifier'] ) ) {
        $n = 1;
        foreach( $licences as $licence ) {
    	$lccid = (integer) $wpdb->get_var( "SELECT lcc_id FROM $nom_table_licences WHERE mbr_id = $id_membre AND fdt_id = $licence->fdt_id;");
    	$wpdb->update(
    			$nom_table_licences,
    			array( 'lcc_numero' => (integer) $_POST['numero' . $n] ),
    			array( 'lcc_id' => $lccid ),
    			array( '%s' ),
    			array( '%d' )
    			);
        $n++; };
    echo '<script type="text/javascript">window.location.href = "localhost:82/wordpress/adherents/" </script>';
    		} ?>
    	</div><!-- #main-fullwidth -->
    <?php get_footer(); ?>

    The issue is undoubtedly in that code but I am not able to find where.
    You are talking of a debugger. I don’t know what you mean exactly. I tested every data queried from the database and stored in the database once update is done. Is that enough? The site is actually in line and the same issue happens.
    Thank you for your interest in my problem, Miflon.

    Hi @miflon,

    It is going to be very difficult for me to point out the issue from the code you have pasted. If you aren’t familiar with basic concepts of programming, like debugging you may need to get professional help. I would recommend seeking help from a professional WordPress developer. That may help get things going faster for you.

    Thread Starter Miflon

    (@miflon)

    At the beginning I just wanted to jump to my home page. I consider that file as resolved. Thank’s for all @tsure.
    Miflon.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘link to another page of the domain’ is closed to new replies.