I have my HTML form code something like this.
<div class="form-group">
<label>Vendor Name <span class="text-danger">*</span>
</label>
<input type="text" name="vendor_name" placeholder="Hello World" class="form-control" required>
</div>
<div class="form-group">
<label>my Domain: <span class="text-danger">*</span>
</label>
<input type="text" name="mailwizz_domain[]" value="" class="form-control" placeholder="https://mailwizz.com">
</div>
<div class="form-group">
<label>Select Required Variables</label>
<select multiple="multiple" name="redirect_url_variables[]" class="form-control redirect_url_variables select" data-fouc>
<option locked="locked" value="FNAME" selected>FNAME</option>
<option value="FROM_NAME">FROM NAME</option>
<option value="FROM_EMAIL">FROM EMAIL</option>
<option value="SUBJECT_LINE">SUBJECT LINE</option>
</select>
</div>
<div class="form-group">
<label>my Domain: <span class="text-danger">*</span>
</label>
<input type="text" name="mailwizz_domain[]" value="" class="form-control" placeholder="https://mailwizz.com">
</div>
<div class="form-group">
<label>Select Required Variables</label>
<select multiple="multiple" name="redirect_url_variables[]" class="form-control redirect_url_variables select" data-fouc>
<option locked="locked" value="FNAME" selected>FNAME</option>
<option value="FROM_NAME">FROM NAME</option>
<option value="FROM_EMAIL">FROM EMAIL</option>
<option value="SUBJECT_LINE">SUBJECT LINE</option>
</select>
</div>
So, here mailwizz_domain and redirect_url_variables are multiple and written with [].
Now, I am posting form data with POST method to PHP and AJAX.
Basically, I am looking for first insert vendor name in vendor table, mailwizz_domain belongs with vendor name so I am inserting in domain list table. Now, redirect_url_variables depends on mailwizz_domain and so I won't insert it for each mailwizz domain in domain_list_variable table. Hence, I am trying like this:
$vendor_name = $_POST['vendor_name'];
$api_endpoint = $_POST['mailwizz_domain'];
//vendor insert code is here
$list_count=count($api_endpoint);
for($k=0; $k<$list_count; $k++){
$api_endpoint_sql = $_POST['mailwizz_domain'][$k];
//domain list insert code here
$redirect_url_variables = $_POST['redirect_url_variables'][$k];
$redirect_url_variables_count = count($redirect_url_variables);
for($v=0; $v<$redirect_url_variables_count; $v++){
$variable = $_POST['redirect_url_variables'][$k][$v];
//variable insert code here
}
}
But, I am getting the below error
PHP Warning: count(): Parameter must be an array or an object that implements Countable in
in line $redirect_url_variables_count = count($redirect_url_variables);
and only one variable is getting inserted with Just First Character called F, even I have selected three variables. My Post in Browser looks like this:
I am not getting an idea of what's wrong with my code. Let me know if anyone here can help me solve the puzzle. Thanks!
