简体   繁体   中英

How to change hidden input field value after form submission in php

I have a form like this :

echo '<input type="hidden" name="un" value="'.$ruser.'">';
echo '<input type="hidden" name="ups" value="'.$rpass.'">';
echo '<input type="hidden" name="fldr" value="'.$cust_fldr.'">';
echo '<input type="text" name="user" value="'.$reg_name.'">';
echo '<input type="text" name="rname" value="'.$rname.'" >';
echo '<input type="submit" name="reg" id="simple-post" value="order" />';

When I click submit button, everything gets posted nicely with ajax exept hidden fields because they are empty at the moment of submission. I should give them values after form submission based on values given on form, before ajax post. How can I do it with php ?

I have googled around but I have not found solution, then I just simply tried this :

$_POST['un'] = $ruser;
$_POST['ups'] = $pass_reg;
$_POST['fldr'] = $cust_fldr;

Then ajax post

ajaxSend($url, $data);

It didn't work either.

Thank you in advance.

First create a function for your submit button. The function will process your data and manipulate the values of your inputs.

echo '<input type="hidden" id="un" name="un" value="'.$ruser.'">';
echo '<input type="hidden" id="ups" name="ups" value="'.$rpass.'">';
echo '<input type="hidden" name="fldr" value="'.$cust_fldr.'">';
echo '<input type="text" name="user" value="'.$reg_name.'">';
echo '<input type="text" name="rname" value="'.$rname.'" >';
echo '<input type="submit" onclick='my_function();return false;' name="reg" id="simple-post" value="order" />';

<script>
function my_function(){
    $('#un').val("THE VALUE");
    $('#ups').val("THE SEC VALUE");
     var url_link = "ajax.php?action=whatever";
     $.ajax({ type: "GET",   
         url: url_link,   
         async: false,
         cache: false,
         success : function(text){
             $('#un').val("CHANGE AGAIN THE VALUE");
         }
     });
}
</script>

This is a small example of what you should use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM