145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign
says

this reply was nonsense

2262 posts
  • Became a Top 20 Author of the Month
  • Had an item that became a weekly top seller
  • Created a helpful tool/app using the Envato API
  • Created a helpful tool/app for Envato Market users
+15 more
revaxarts
says

try “disabled” instead of “readonly”

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign
says

Any Ideas?

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
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
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign
says

edit.

by
by
by
by
by
by