ThemeForest

Update Post 2 times to save readonly textfield (Metaboxes)

123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

I have to save my post two times to get the variable $event_realstartdate saved. I understand why it is but don’t know how to rewrite it.

I have a textfield “event_startdate”. When the user changes this textfield, it calculates the content of a readonly textfield “event_realstartdate”.

When clicking on Update once, the readonly textfield is calculated correctly but it’s not “transfered”, so that I could use it on my page.

<input type="text" id="event_startdate" name="event_startdate" value="<?php echo $event_startdate; ?>">

<?php include( 'calculation.php' ); $event_realstartdate = $event_startdate; ?>
<input type="text" readonly id="event_realstartdate" name="event_realstartdate" value="<?php echo $event_realstartdate; ?>">
if(isset($_POST['event_startdate'])) {  
        update_post_meta($post_id, 'event_startdate', esc_attr( $_POST['event_startdate']) );
    }    
if(isset($_POST['event_realstartdate'])) {  
        update_post_meta($post_id, 'event_realstartdate', esc_attr( $_POST['event_realstartdate']) );
}    
123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

this reply was nonsense

1763 posts
  • Microlancer Beta Tester
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 3-4 years
  • Austria
  • Exclusive Author
  • Referred between 200 and 499 users
+2 more
revaxarts says

try “disabled” instead of “readonly”

123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

no then it doesn’t work anymore. There’s no problem with readonly.

The problem is that the correct content in the readonly field is only available after saving the first time. After saving the second time, the variable gets the content of the readonly field.

Everything should be done when saving the first time

123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

Any Ideas?

123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

Hi, thank you for helping. I already tried it similar to your version:

if(isset($_POST['event_startdate'])) {  
    update_post_meta($post_id, 'event_startdate', esc_attr( $_POST['event_startdate']) );
        include( 'recurring-calculation.php' ); 
$_POST['event_realstartdate'] = $_POST['event_startdate'];
    update_post_meta($post_id, 'event_realstartdate', esc_attr( $_POST['event_realstartdate']) );    
}    

But I always get this error message when updating the post:

Warning: Cannot modify header information - headers already sent by (output started at C:\iwpserver\htdocs\wordpress\wp-content\themes\eventix\includes\recurring-calculation.php:3) in C:\iwpserver\htdocs\wordpress\wp-includes\pluggable.php on line 881

This error message is only because of the include function. Doesn’t matter what I write in this php file (even if it’s empty). If I remove this include, it would work.

Is there another way instead of posting the whole php file in my metaboxes.php ?

123 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 0-1 years
LovelessDesign says

edit.

by
by
by
by
by