开发者

PHP Array'd POST Variable Name

开发者 https://www.devze.com 2023-04-04 14:08 出处:网络
Using the following code I am attempting to: Test to see if one of the dynamically assigned field names has been submitted;

Using the following code I am attempting to:

  1. Test to see if one of the dynamically assigned field names has been submitted;
  2. Use the "Actionable Code" to process the submitted information.

My problem lies in I am incapable of retrieving the appropriate dynamic variable name. $this->get_field_name('email_to') will output a name variable such as widget-mywidget[3][email_to]; but to access this value via PHP I need it in the form of $_POST['widget-mywidget'][3]['email_to'].

How can I go about solvi开发者_运维问答ng this dilemma?

OUTPUTTED HTML:

<form id="widget-mywidget-3-osiris_contact" method="post" action="">
<fieldset>
<input type="text" name="widget-mywidget[3][user_name]">
<input type="text" name="widget-mywidget[3][user_email]">
<textarea name="widget-mywidget[3][user_message]"></textarea>
</fieldset>
<fieldset>
<input type="hidden" name="widget-mywidget[3][email_to]" value="">
<input type="hidden" name="widget-mywidget[3][email_subject]" value="">
<button type="submit" name="widget-mywidget[3][email_send]">Send</button>
</fieldset>
</form>

PROCESSING PHP:

if(in_array($this->get_field_name('email_to'), $_POST)){ // <--- Where I need help.
    // Actionable Code
}


This is what $this->get_field_name does:

  function get_field_name($field_name) {
     return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
  }

I suggest that you print_r($_POST) and compare it visually for better debugging...
(Or use a debugger...)


$thing  = "widget-mywidget[3][email_to]";
$exp    = explode("[", $thing);
$get_it = $_POST['".$exp[0]."[".$exp[1]."[".$exp[2]."'];

Try, if it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消