php - Updating different forms at the same time -


current situation

so, follow question previous question (submit button affect multiple files)

the approach in terms of how "click" multiple buttons using "super-button" (patent pending) @omikey. supposed do, clicking buttons.

the mark up following:

title.php

    <form role="form" method="post">                             <div class="edit_title">              <input type="hidden" value="<?php echo $post_id; ?>">              <?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'article title..', 'value' => $post->post_title ) ); ?>             <div class="update-button-wrap">                  <input id="save_button" type="submit" name="update_product" value="<?php esc_attr_e( 'update', 'site' ); ?>"/>             </div>           </div>                       </form> 

content.php

 <form role="form" method="post">                            <div class="edit_content">             <?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'short description..', 'value' => $post->post_content ), 'textarea' ); ?>         </div>         <div class="update-button-wrap">             <input id="save_button" type="submit" name="update_product" value="<?php esc_attr_e( 'update', 'site' ); ?>"/>         </div>                           </form> 

article.php

<button type='button' onclick="$('[type="submit"]').click()">submit</button> 

problem

so, when "submit" button clicked, both buttons in each title.php , content.php clicked (ie. in regards clicking buttons, works fine). however, because 2 forms simultaneously clicked, second 1 updated (either content or title) while first 1 ignored, when both data needed updated.

my approach

now, can merge 2 files , have both title , content within single form, messes overall setup , heard better have multiple smaller php files updating , speed large 1 big file.

or here approach.

in article.php, have form , submit button while title.php , content.php has editable forms. these 2 forms somehow linked form in article.php, image below.

enter image description here

do think second approach can achieved or other suggestions?

thanks

just add global form on article.php , drop title , content forms (and submit buttons). every named input inside global form submitted no matter php file generated them.

edit: title.php

<div class="edit_title">      <input type="hidden" value="<?php echo $post_id; ?>">      <?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'article title..', 'value' => $post->post_title ) ); ?> </div> 

content.php

<div class="edit_content">     <?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'short description..', 'value' => $post->post_content ), 'textarea' ); ?> </div> 

article.php

<form role="form" method="post"> <?php include "title.php"; include "content.php"; ?> <button type='submit'>submit</button> </form> 

option 2: alternatively use sort of functionality allows create forms once, if have "inner forms". way title.php , content.php work standalone code snippets.

$formdeep = 0; function openform() {     global $formdeep;     if ($formdeep == 0) {         echo "<form role=\"form\" method=\"post\">";     }     $formdeep++; }  function closeform() {     global $formdeep;     $formdeep--;     if ($formdeep == 0) {         echo "</form>";     } } 

title.php

<?php openform(); ?> <div class="edit_title">      <input type="hidden" value="<?php echo $post_id; ?>">      <?php post_input_box( $post_id, 'post_title', array( 'placeholder' => 'article title..', 'value' => $post->post_title ) ); ?> </div> <?php closeform(); ?> 

content.php

<?php openform(); ?> <div class="edit_content">     <?php post_input_box( $post_id, 'post_content', array( 'placeholder' => 'short description..', 'value' => $post->post_content ), 'textarea' ); ?> </div> <?php closeform(); ?> 

article.php

<?php openform(); ?> <?php include "title.php"; include "content.php"; ?> <button type='submit'>submit</button> <?php closeform(); ?> 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -