145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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']) );
}    
145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

this reply was nonsense

2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+15 more
revaxarts
says

try “disabled” instead of “readonly”

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

Any Ideas?

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
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 ?

145 posts
  • 3 Years of Membership
  • Austria
  • Collector Level 1
  • Exclusive Author
LovelessDesign
says

edit.

by
by
by
by
by
by