0

Hello i have fallowing post input data

i am trying to update localize file which is json format it has 524 Lines, and output is success

{
    "loading_js_content":"Loading Javascript Content...",
    "offical_site":"Official Site",
    "Online_users":"Online Users",
    ......
    .....
   ......
and go on

}

html

<form method="POST" action="" id="lang_file"  class="FormBlock">    
<table class="ranktable">
    <tr class="head" >
        <td colspan="2" id="boxTitle">Edit/Update <?php echo $LangName; ?> Values</td>
    </tr>
    <tr class="head">
        <td>#</td>
        <td>Key</td>
        <td>Value</td>
    </tr>
    <?php 
        $i = 0; 
        foreach($LangData as $key => $value):   
        $i++; 
        $class = ($i%2==0) ? 'alt1' : 'alt2';

    ?>

    <tr class="<?php echo $class; ?>">
            <td><?php echo $i; ?></td>
        <td style="text-align:left">
            <input type="text" name="lang_key[]" class="formatted"  value="<?php echo $key; ?>" style="width:150px;"  />    
        </td>
        <td style="text-align:left">
            <input type="text" name="lang_val[]" class="formatted"  value="<?php echo $value; ?>" style="width:380px;"  />  
        </td>
    </tr>   
    <?php endforeach; ?>

</table>
  1. The problem is when getting post. Count $_POST['lang_key'] is 500 lines instate of 524.24 line is missing affter line 500.

  2. How can i write it to file back as same format ? i have fallowing code as far as i can do

foreach( $_POST['lang_key'] as   $lang_key => $key)
{
    $data[] = $key;
}

foreach( $_POST['lang_value'] as $lang_value => $val)
{
    $data[] = $val;
}

file_put_contents(BASE_DIRECTORY.'test.json',json_encode($data,JSON_PRETTY_PRINT));

2 Answers 2

1

You need to use the lang_key parameters as the keys in the associative array, and lang_value as the corresponding values.

foreach ($_POST['lang_key'] as $index => $key) {
    $data[$key] = $_POST['lang_value'][$index];
}

I don't know why you're only getting 500 inputs, though.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for fixed write as json format. but still get missied inputs count. When i print out with loop foreach it success. displays whole lines. really weird. Any limit of getting inputs?
1

I got the solution after some search. The problem is comes from max_input_vars in php.ini: its default is 1000. So when I try to post 500 -> lang_key and 500 -> lang_value it's oversize it.

So the solution is change php.ini -> max_input_vars to bigger value and no more issues.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.